Laura Cuna, 20211312
Amelie Langenstein, 20210637
Tongjiuzhou Liu, 20211012
Nina Urbancic, 20211314
import numpy as np
import pandas as pd
from functools import reduce
from datetime import datetime, timedelta
from sklearn.metrics import mean_squared_error,mean_absolute_error
from math import sqrt
from sklearn.preprocessing import StandardScaler
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import plotly.express as px
import matplotlib.pyplot as plt
from statsmodels.tsa.api import ExponentialSmoothing, SimpleExpSmoothing, Holt
import statsmodels.api as sm
from autots import AutoTS
from sklearn import linear_model, svm ,tree
from sklearn.ensemble import RandomForestRegressor, GradientBoostingRegressor
from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels import DotProduct, WhiteKernel
from sklearn.neural_network import MLPRegressor
import warnings
warnings.filterwarnings("ignore")
warnings.simplefilter(action='ignore', category=FutureWarning)
warnings.simplefilter(action='ignore', category=DeprecationWarning)
# Read csv files
df_adj_close = pd.read_csv('data_updated/adj_close.csv')
df_close = pd.read_csv('data_updated/close.csv')
df_high = pd.read_csv('data_updated/high.csv')
df_low = pd.read_csv('data_updated/low.csv')
df_open = pd.read_csv('data_updated/open.csv')
df_volume = pd.read_csv('data_updated/volume.csv')
#display df_adj_close info
df_adj_close .info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 1826 entries, 0 to 1825 Data columns (total 11 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Date 1826 non-null object 1 ADA-USD 1642 non-null float64 2 ATOM-USD 1152 non-null float64 3 AVAX-USD 596 non-null float64 4 AXS-USD 551 non-null float64 5 BTC-USD 1826 non-null float64 6 ETH-USD 1642 non-null float64 7 LINK-USD 1642 non-null float64 8 LUNA1-USD 1018 non-null float64 9 MATIC-USD 1107 non-null float64 10 SOL-USD 759 non-null float64 dtypes: float64(10), object(1) memory usage: 157.0+ KB
#display top rows
df_adj_close.head(10)
| Date | ADA-USD | ATOM-USD | AVAX-USD | AXS-USD | BTC-USD | ETH-USD | LINK-USD | LUNA1-USD | MATIC-USD | SOL-USD | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 2017-05-09 | NaN | NaN | NaN | NaN | 1755.359985 | NaN | NaN | NaN | NaN | NaN |
| 1 | 2017-05-10 | NaN | NaN | NaN | NaN | 1787.130005 | NaN | NaN | NaN | NaN | NaN |
| 2 | 2017-05-11 | NaN | NaN | NaN | NaN | 1848.569946 | NaN | NaN | NaN | NaN | NaN |
| 3 | 2017-05-12 | NaN | NaN | NaN | NaN | 1724.239990 | NaN | NaN | NaN | NaN | NaN |
| 4 | 2017-05-13 | NaN | NaN | NaN | NaN | 1804.910034 | NaN | NaN | NaN | NaN | NaN |
| 5 | 2017-05-14 | NaN | NaN | NaN | NaN | 1808.910034 | NaN | NaN | NaN | NaN | NaN |
| 6 | 2017-05-15 | NaN | NaN | NaN | NaN | 1738.430054 | NaN | NaN | NaN | NaN | NaN |
| 7 | 2017-05-16 | NaN | NaN | NaN | NaN | 1734.449951 | NaN | NaN | NaN | NaN | NaN |
| 8 | 2017-05-17 | NaN | NaN | NaN | NaN | 1839.089966 | NaN | NaN | NaN | NaN | NaN |
| 9 | 2017-05-18 | NaN | NaN | NaN | NaN | 1888.650024 | NaN | NaN | NaN | NaN | NaN |
# Statistics summary for all variables
df_adj_close.describe(include='all').transpose()
| count | unique | top | freq | mean | std | min | 25% | 50% | 75% | max | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Date | 1826 | 1826 | 2017-05-09 | 1 | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
| ADA-USD | 1642.0 | NaN | NaN | NaN | 0.497968 | 0.666615 | 0.023961 | 0.055433 | 0.122827 | 0.909644 | 2.968239 |
| ATOM-USD | 1152.0 | NaN | NaN | NaN | 12.216874 | 11.210744 | 1.649203 | 3.806889 | 5.443107 | 21.197567 | 44.542789 |
| AVAX-USD | 596.0 | NaN | NaN | NaN | 43.464394 | 34.932014 | 2.906161 | 11.946604 | 33.190775 | 73.774998 | 134.531036 |
| AXS-USD | 551.0 | NaN | NaN | NaN | 43.420527 | 44.710141 | 0.135104 | 3.862872 | 38.826496 | 69.074894 | 160.359268 |
| BTC-USD | 1826.0 | NaN | NaN | NaN | 18304.206377 | 17684.742637 | 1724.23999 | 6545.862671 | 9346.422852 | 33740.259766 | 67566.828125 |
| ETH-USD | 1642.0 | NaN | NaN | NaN | 1082.087933 | 1259.103359 | 84.308296 | 197.894001 | 396.122879 | 1833.355743 | 4812.087402 |
| LINK-USD | 1642.0 | NaN | NaN | NaN | 9.295461 | 11.054522 | 0.145255 | 0.495084 | 2.829861 | 15.957991 | 52.198696 |
| LUNA1-USD | 1018.0 | NaN | NaN | NaN | 18.671399 | 29.154327 | 0.125335 | 0.303977 | 1.134158 | 29.85543 | 116.40892 |
| MATIC-USD | 1107.0 | NaN | NaN | NaN | 0.551182 | 0.745818 | 0.003141 | 0.016688 | 0.023088 | 1.257664 | 2.876757 |
| SOL-USD | 759.0 | NaN | NaN | NaN | 57.045539 | 68.432985 | 0.515273 | 2.156908 | 27.702082 | 99.549286 | 258.934326 |
#display df_close info
df_close .info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 1826 entries, 0 to 1825 Data columns (total 11 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Date 1826 non-null object 1 ADA-USD 1642 non-null float64 2 ATOM-USD 1152 non-null float64 3 AVAX-USD 596 non-null float64 4 AXS-USD 551 non-null float64 5 BTC-USD 1826 non-null float64 6 ETH-USD 1642 non-null float64 7 LINK-USD 1642 non-null float64 8 LUNA1-USD 1018 non-null float64 9 MATIC-USD 1107 non-null float64 10 SOL-USD 759 non-null float64 dtypes: float64(10), object(1) memory usage: 157.0+ KB
#display top rows
df_close.head(10)
| Date | ADA-USD | ATOM-USD | AVAX-USD | AXS-USD | BTC-USD | ETH-USD | LINK-USD | LUNA1-USD | MATIC-USD | SOL-USD | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 2017-05-09 | NaN | NaN | NaN | NaN | 1755.359985 | NaN | NaN | NaN | NaN | NaN |
| 1 | 2017-05-10 | NaN | NaN | NaN | NaN | 1787.130005 | NaN | NaN | NaN | NaN | NaN |
| 2 | 2017-05-11 | NaN | NaN | NaN | NaN | 1848.569946 | NaN | NaN | NaN | NaN | NaN |
| 3 | 2017-05-12 | NaN | NaN | NaN | NaN | 1724.239990 | NaN | NaN | NaN | NaN | NaN |
| 4 | 2017-05-13 | NaN | NaN | NaN | NaN | 1804.910034 | NaN | NaN | NaN | NaN | NaN |
| 5 | 2017-05-14 | NaN | NaN | NaN | NaN | 1808.910034 | NaN | NaN | NaN | NaN | NaN |
| 6 | 2017-05-15 | NaN | NaN | NaN | NaN | 1738.430054 | NaN | NaN | NaN | NaN | NaN |
| 7 | 2017-05-16 | NaN | NaN | NaN | NaN | 1734.449951 | NaN | NaN | NaN | NaN | NaN |
| 8 | 2017-05-17 | NaN | NaN | NaN | NaN | 1839.089966 | NaN | NaN | NaN | NaN | NaN |
| 9 | 2017-05-18 | NaN | NaN | NaN | NaN | 1888.650024 | NaN | NaN | NaN | NaN | NaN |
# Statistics summary for all variables
df_close.describe(include='all').transpose()
| count | unique | top | freq | mean | std | min | 25% | 50% | 75% | max | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Date | 1826 | 1826 | 2017-05-09 | 1 | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
| ADA-USD | 1642.0 | NaN | NaN | NaN | 0.497968 | 0.666615 | 0.023961 | 0.055433 | 0.122827 | 0.909644 | 2.968239 |
| ATOM-USD | 1152.0 | NaN | NaN | NaN | 12.216874 | 11.210744 | 1.649203 | 3.806889 | 5.443107 | 21.197567 | 44.542789 |
| AVAX-USD | 596.0 | NaN | NaN | NaN | 43.464394 | 34.932014 | 2.906161 | 11.946604 | 33.190775 | 73.774998 | 134.531036 |
| AXS-USD | 551.0 | NaN | NaN | NaN | 43.420527 | 44.710141 | 0.135104 | 3.862872 | 38.826496 | 69.074894 | 160.359268 |
| BTC-USD | 1826.0 | NaN | NaN | NaN | 18304.206377 | 17684.742637 | 1724.23999 | 6545.862671 | 9346.422852 | 33740.259766 | 67566.828125 |
| ETH-USD | 1642.0 | NaN | NaN | NaN | 1082.087933 | 1259.103359 | 84.308296 | 197.894001 | 396.122879 | 1833.355743 | 4812.087402 |
| LINK-USD | 1642.0 | NaN | NaN | NaN | 9.295461 | 11.054522 | 0.145255 | 0.495084 | 2.829861 | 15.957991 | 52.198696 |
| LUNA1-USD | 1018.0 | NaN | NaN | NaN | 18.671399 | 29.154327 | 0.125335 | 0.303977 | 1.134158 | 29.85543 | 116.40892 |
| MATIC-USD | 1107.0 | NaN | NaN | NaN | 0.551182 | 0.745818 | 0.003141 | 0.016688 | 0.023088 | 1.257664 | 2.876757 |
| SOL-USD | 759.0 | NaN | NaN | NaN | 57.045539 | 68.432985 | 0.515273 | 2.156908 | 27.702082 | 99.549286 | 258.934326 |
#display df_close info
df_high .info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 1826 entries, 0 to 1825 Data columns (total 11 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Date 1826 non-null object 1 ADA-USD 1642 non-null float64 2 ATOM-USD 1152 non-null float64 3 AVAX-USD 596 non-null float64 4 AXS-USD 551 non-null float64 5 BTC-USD 1826 non-null float64 6 ETH-USD 1642 non-null float64 7 LINK-USD 1642 non-null float64 8 LUNA1-USD 1018 non-null float64 9 MATIC-USD 1107 non-null float64 10 SOL-USD 759 non-null float64 dtypes: float64(10), object(1) memory usage: 157.0+ KB
#display top rows
df_high.head(10)
| Date | ADA-USD | ATOM-USD | AVAX-USD | AXS-USD | BTC-USD | ETH-USD | LINK-USD | LUNA1-USD | MATIC-USD | SOL-USD | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 2017-05-09 | NaN | NaN | NaN | NaN | 1833.489990 | NaN | NaN | NaN | NaN | NaN |
| 1 | 2017-05-10 | NaN | NaN | NaN | NaN | 1788.439941 | NaN | NaN | NaN | NaN | NaN |
| 2 | 2017-05-11 | NaN | NaN | NaN | NaN | 1873.930054 | NaN | NaN | NaN | NaN | NaN |
| 3 | 2017-05-12 | NaN | NaN | NaN | NaN | 1856.150024 | NaN | NaN | NaN | NaN | NaN |
| 4 | 2017-05-13 | NaN | NaN | NaN | NaN | 1812.989990 | NaN | NaN | NaN | NaN | NaN |
| 5 | 2017-05-14 | NaN | NaN | NaN | NaN | 1831.420044 | NaN | NaN | NaN | NaN | NaN |
| 6 | 2017-05-15 | NaN | NaN | NaN | NaN | 1812.800049 | NaN | NaN | NaN | NaN | NaN |
| 7 | 2017-05-16 | NaN | NaN | NaN | NaN | 1785.939941 | NaN | NaN | NaN | NaN | NaN |
| 8 | 2017-05-17 | NaN | NaN | NaN | NaN | 1864.050049 | NaN | NaN | NaN | NaN | NaN |
| 9 | 2017-05-18 | NaN | NaN | NaN | NaN | 1904.479980 | NaN | NaN | NaN | NaN | NaN |
# Statistics summary for all variables
df_high.describe(include='all').transpose()
| count | unique | top | freq | mean | std | min | 25% | 50% | 75% | max | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Date | 1826 | 1826 | 2017-05-09 | 1 | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
| ADA-USD | 1642.0 | NaN | NaN | NaN | 0.519736 | 0.694786 | 0.025993 | 0.057308 | 0.126603 | 0.948726 | 3.099186 |
| ATOM-USD | 1152.0 | NaN | NaN | NaN | 12.854746 | 11.811977 | 1.813534 | 3.997958 | 5.694305 | 22.243774 | 44.695526 |
| AVAX-USD | 596.0 | NaN | NaN | NaN | 45.925314 | 36.631405 | 2.939915 | 12.620885 | 35.647593 | 77.035427 | 146.217865 |
| AXS-USD | 551.0 | NaN | NaN | NaN | 45.79879 | 46.991889 | 0.149547 | 4.148534 | 42.817684 | 73.367615 | 165.36908 |
| BTC-USD | 1826.0 | NaN | NaN | NaN | 18769.671052 | 18144.944936 | 1785.939941 | 6643.27002 | 9522.317871 | 34790.40918 | 68789.625 |
| ETH-USD | 1642.0 | NaN | NaN | NaN | 1116.825753 | 1297.985013 | 85.342743 | 203.844898 | 410.578644 | 1874.482544 | 4891.70459 |
| LINK-USD | 1642.0 | NaN | NaN | NaN | 9.735538 | 11.610559 | 0.166283 | 0.516995 | 2.940955 | 16.626945 | 52.876087 |
| LUNA1-USD | 1018.0 | NaN | NaN | NaN | 19.616367 | 30.482232 | 0.137031 | 0.315553 | 1.181119 | 31.841465 | 119.184624 |
| MATIC-USD | 1107.0 | NaN | NaN | NaN | 0.581249 | 0.78592 | 0.00338 | 0.017401 | 0.024906 | 1.341377 | 2.923235 |
| SOL-USD | 759.0 | NaN | NaN | NaN | 59.77336 | 71.373131 | 0.559759 | 2.287922 | 28.797941 | 102.721939 | 260.062103 |
#display df_close info
df_low.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 1826 entries, 0 to 1825 Data columns (total 11 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Date 1826 non-null object 1 ADA-USD 1642 non-null float64 2 ATOM-USD 1152 non-null float64 3 AVAX-USD 596 non-null float64 4 AXS-USD 551 non-null float64 5 BTC-USD 1826 non-null float64 6 ETH-USD 1642 non-null float64 7 LINK-USD 1642 non-null float64 8 LUNA1-USD 1018 non-null float64 9 MATIC-USD 1107 non-null float64 10 SOL-USD 759 non-null float64 dtypes: float64(10), object(1) memory usage: 157.0+ KB
#display top rows
df_low.head(10)
| Date | ADA-USD | ATOM-USD | AVAX-USD | AXS-USD | BTC-USD | ETH-USD | LINK-USD | LUNA1-USD | MATIC-USD | SOL-USD | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 2017-05-09 | NaN | NaN | NaN | NaN | 1716.300049 | NaN | NaN | NaN | NaN | NaN |
| 1 | 2017-05-10 | NaN | NaN | NaN | NaN | 1719.099976 | NaN | NaN | NaN | NaN | NaN |
| 2 | 2017-05-11 | NaN | NaN | NaN | NaN | 1755.349976 | NaN | NaN | NaN | NaN | NaN |
| 3 | 2017-05-12 | NaN | NaN | NaN | NaN | 1694.010010 | NaN | NaN | NaN | NaN | NaN |
| 4 | 2017-05-13 | NaN | NaN | NaN | NaN | 1651.079956 | NaN | NaN | NaN | NaN | NaN |
| 5 | 2017-05-14 | NaN | NaN | NaN | NaN | 1776.619995 | NaN | NaN | NaN | NaN | NaN |
| 6 | 2017-05-15 | NaN | NaN | NaN | NaN | 1708.540039 | NaN | NaN | NaN | NaN | NaN |
| 7 | 2017-05-16 | NaN | NaN | NaN | NaN | 1686.540039 | NaN | NaN | NaN | NaN | NaN |
| 8 | 2017-05-17 | NaN | NaN | NaN | NaN | 1661.910034 | NaN | NaN | NaN | NaN | NaN |
| 9 | 2017-05-18 | NaN | NaN | NaN | NaN | 1807.119995 | NaN | NaN | NaN | NaN | NaN |
# Statistics summary for all variables
df_low.describe(include='all').transpose()
| count | unique | top | freq | mean | std | min | 25% | 50% | 75% | max | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Date | 1826 | 1826 | 2017-05-09 | 1 | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
| ADA-USD | 1642.0 | NaN | NaN | NaN | 0.473749 | 0.63658 | 0.01913 | 0.052654 | 0.116842 | 0.868356 | 2.907606 |
| ATOM-USD | 1152.0 | NaN | NaN | NaN | 11.543354 | 10.565706 | 1.130963 | 3.66315 | 5.232173 | 19.613737 | 39.223259 |
| AVAX-USD | 596.0 | NaN | NaN | NaN | 41.073355 | 33.340919 | 2.788822 | 11.178039 | 30.970074 | 70.998224 | 126.192612 |
| AXS-USD | 551.0 | NaN | NaN | NaN | 41.389273 | 42.977619 | 0.123431 | 3.486876 | 37.413174 | 66.126862 | 154.217072 |
| BTC-USD | 1826.0 | NaN | NaN | NaN | 17756.186956 | 17159.861264 | 1651.079956 | 6449.152466 | 9201.932617 | 32267.986816 | 66382.0625 |
| ETH-USD | 1642.0 | NaN | NaN | NaN | 1040.537679 | 1214.59605 | 82.829887 | 193.814362 | 385.383759 | 1762.860291 | 4718.039062 |
| LINK-USD | 1642.0 | NaN | NaN | NaN | 8.800956 | 10.415494 | 0.137963 | 0.473691 | 2.734456 | 15.238159 | 46.729218 |
| LUNA1-USD | 1018.0 | NaN | NaN | NaN | 17.678475 | 27.789968 | 0.120116 | 0.292372 | 1.089132 | 26.976658 | 114.112862 |
| MATIC-USD | 1107.0 | NaN | NaN | NaN | 0.520422 | 0.705784 | 0.003012 | 0.015792 | 0.021874 | 1.192232 | 2.71271 |
| SOL-USD | 759.0 | NaN | NaN | NaN | 54.185221 | 65.325787 | 0.505194 | 2.015429 | 25.94908 | 95.210335 | 246.122421 |
#display df_close info
df_open.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 1826 entries, 0 to 1825 Data columns (total 11 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Date 1826 non-null object 1 ADA-USD 1642 non-null float64 2 ATOM-USD 1152 non-null float64 3 AVAX-USD 596 non-null float64 4 AXS-USD 551 non-null float64 5 BTC-USD 1826 non-null float64 6 ETH-USD 1642 non-null float64 7 LINK-USD 1642 non-null float64 8 LUNA1-USD 1018 non-null float64 9 MATIC-USD 1107 non-null float64 10 SOL-USD 759 non-null float64 dtypes: float64(10), object(1) memory usage: 157.0+ KB
#display top rows
df_open.head(10)
| Date | ADA-USD | ATOM-USD | AVAX-USD | AXS-USD | BTC-USD | ETH-USD | LINK-USD | LUNA1-USD | MATIC-USD | SOL-USD | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 2017-05-09 | NaN | NaN | NaN | NaN | 1723.890015 | NaN | NaN | NaN | NaN | NaN |
| 1 | 2017-05-10 | NaN | NaN | NaN | NaN | 1756.520020 | NaN | NaN | NaN | NaN | NaN |
| 2 | 2017-05-11 | NaN | NaN | NaN | NaN | 1780.369995 | NaN | NaN | NaN | NaN | NaN |
| 3 | 2017-05-12 | NaN | NaN | NaN | NaN | 1845.760010 | NaN | NaN | NaN | NaN | NaN |
| 4 | 2017-05-13 | NaN | NaN | NaN | NaN | 1723.119995 | NaN | NaN | NaN | NaN | NaN |
| 5 | 2017-05-14 | NaN | NaN | NaN | NaN | 1800.859985 | NaN | NaN | NaN | NaN | NaN |
| 6 | 2017-05-15 | NaN | NaN | NaN | NaN | 1808.439941 | NaN | NaN | NaN | NaN | NaN |
| 7 | 2017-05-16 | NaN | NaN | NaN | NaN | 1741.699951 | NaN | NaN | NaN | NaN | NaN |
| 8 | 2017-05-17 | NaN | NaN | NaN | NaN | 1726.729980 | NaN | NaN | NaN | NaN | NaN |
| 9 | 2017-05-18 | NaN | NaN | NaN | NaN | 1818.699951 | NaN | NaN | NaN | NaN | NaN |
# Statistics summary for all variables
df_open.describe(include='all').transpose()
| count | unique | top | freq | mean | std | min | 25% | 50% | 75% | max | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Date | 1826 | 1826 | 2017-05-09 | 1 | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
| ADA-USD | 1642.0 | NaN | NaN | NaN | 0.497528 | 0.666607 | 0.023954 | 0.055242 | 0.122547 | 0.913276 | 2.96639 |
| ATOM-USD | 1152.0 | NaN | NaN | NaN | 12.210296 | 11.212199 | 1.6523 | 3.804252 | 5.446188 | 21.240587 | 44.279644 |
| AVAX-USD | 596.0 | NaN | NaN | NaN | 43.377223 | 34.947575 | 2.905293 | 11.931973 | 32.987362 | 73.753132 | 134.865555 |
| AXS-USD | 551.0 | NaN | NaN | NaN | 43.381607 | 44.767922 | 0.135104 | 3.828733 | 38.822624 | 69.179169 | 160.62056 |
| BTC-USD | 1826.0 | NaN | NaN | NaN | 18288.866123 | 17689.674376 | 1723.119995 | 6546.864868 | 9346.383789 | 33713.331055 | 67549.734375 |
| ETH-USD | 1642.0 | NaN | NaN | NaN | 1080.989378 | 1259.259784 | 84.279694 | 198.229 | 395.791153 | 1829.884399 | 4810.071289 |
| LINK-USD | 1642.0 | NaN | NaN | NaN | 9.290156 | 11.057235 | 0.14736 | 0.494952 | 2.827238 | 15.94794 | 52.247688 |
| LUNA1-USD | 1018.0 | NaN | NaN | NaN | 18.614501 | 29.128129 | 0.125335 | 0.303746 | 1.134708 | 29.885582 | 116.419167 |
| MATIC-USD | 1107.0 | NaN | NaN | NaN | 0.550599 | 0.746438 | 0.003143 | 0.016689 | 0.022967 | 1.25759 | 2.876459 |
| SOL-USD | 759.0 | NaN | NaN | NaN | 56.981701 | 68.524436 | 0.513391 | 2.151117 | 27.408316 | 99.578991 | 258.781555 |
#display df_close info
df_volume.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 1826 entries, 0 to 1825 Data columns (total 11 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Date 1826 non-null object 1 ADA-USD 1642 non-null float64 2 ATOM-USD 1152 non-null float64 3 AVAX-USD 596 non-null float64 4 AXS-USD 551 non-null float64 5 BTC-USD 1826 non-null int64 6 ETH-USD 1642 non-null float64 7 LINK-USD 1642 non-null float64 8 LUNA1-USD 1018 non-null float64 9 MATIC-USD 1107 non-null float64 10 SOL-USD 759 non-null float64 dtypes: float64(9), int64(1), object(1) memory usage: 157.0+ KB
#display top rows
df_volume.head(10)
| Date | ADA-USD | ATOM-USD | AVAX-USD | AXS-USD | BTC-USD | ETH-USD | LINK-USD | LUNA1-USD | MATIC-USD | SOL-USD | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 2017-05-09 | NaN | NaN | NaN | NaN | 1167920000 | NaN | NaN | NaN | NaN | NaN |
| 1 | 2017-05-10 | NaN | NaN | NaN | NaN | 915723008 | NaN | NaN | NaN | NaN | NaN |
| 2 | 2017-05-11 | NaN | NaN | NaN | NaN | 799489984 | NaN | NaN | NaN | NaN | NaN |
| 3 | 2017-05-12 | NaN | NaN | NaN | NaN | 740984000 | NaN | NaN | NaN | NaN | NaN |
| 4 | 2017-05-13 | NaN | NaN | NaN | NaN | 579635008 | NaN | NaN | NaN | NaN | NaN |
| 5 | 2017-05-14 | NaN | NaN | NaN | NaN | 437196000 | NaN | NaN | NaN | NaN | NaN |
| 6 | 2017-05-15 | NaN | NaN | NaN | NaN | 731529024 | NaN | NaN | NaN | NaN | NaN |
| 7 | 2017-05-16 | NaN | NaN | NaN | NaN | 959044992 | NaN | NaN | NaN | NaN | NaN |
| 8 | 2017-05-17 | NaN | NaN | NaN | NaN | 1064729984 | NaN | NaN | NaN | NaN | NaN |
| 9 | 2017-05-18 | NaN | NaN | NaN | NaN | 894321024 | NaN | NaN | NaN | NaN | NaN |
# Statistics summary for all variables
df_volume.describe(include='all').transpose()
| count | unique | top | freq | mean | std | min | 25% | 50% | 75% | max | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Date | 1826 | 1826 | 2017-05-09 | 1 | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
| ADA-USD | 1642.0 | NaN | NaN | NaN | 1203557557.314251 | 2174168383.667414 | 2930550.0 | 65618150.0 | 201408034.0 | 1374642211.75 | 19141980288.0 |
| ATOM-USD | 1152.0 | NaN | NaN | NaN | 447252034.90625 | 531909209.203074 | 2567201.0 | 138030654.25 | 237384967.0 | 557282797.25 | 4260699810.0 |
| AVAX-USD | 596.0 | NaN | NaN | NaN | 624765034.45302 | 662903475.609255 | 3957.0 | 76682100.5 | 383878398.5 | 993495407.25 | 3379295976.0 |
| AXS-USD | 551.0 | NaN | NaN | NaN | 433528253.430127 | 733799319.917523 | 579626.0 | 23692772.0 | 241718626.0 | 510260634.5 | 6680961800.0 |
| BTC-USD | 1826.0 | NaN | NaN | NaN | 22986761694.782036 | 20570022859.043835 | 437196000.0 | 5773257656.0 | 19402408850.5 | 33698307972.5 | 350967941479.0 |
| ETH-USD | 1642.0 | NaN | NaN | NaN | 12565903550.794762 | 11110642488.81424 | 621732992.0 | 3345382822.25 | 9822888936.0 | 17984202349.75 | 84482912776.0 |
| LINK-USD | 1642.0 | NaN | NaN | NaN | 781467977.721072 | 4297139145.322037 | 398773.0 | 8439840.0 | 236902927.5 | 1068083975.25 | 170549323809.0 |
| LUNA1-USD | 1018.0 | NaN | NaN | NaN | 600746700.342829 | 1019363153.967797 | 170533.0 | 3349351.75 | 21165924.5 | 781371636.0 | 6147402521.0 |
| MATIC-USD | 1107.0 | NaN | NaN | NaN | 539981290.908762 | 990457896.530861 | 2938835.0 | 17862203.0 | 54098105.0 | 751638658.0 | 9181248216.0 |
| SOL-USD | 759.0 | NaN | NaN | NaN | 1108253016.791831 | 1645131325.804039 | 652020.0 | 13231785.0 | 353750758.0 | 1845294915.5 | 17068643416.0 |
# merge all the data in one dataframe
dfs = [df_adj_close, df_close, df_high, df_low,df_open,df_volume]
df_total = reduce(lambda left,right: pd.merge(left,right,on='Date'), dfs)
df_total
| Date | ADA-USD_x | ATOM-USD_x | AVAX-USD_x | AXS-USD_x | BTC-USD_x | ETH-USD_x | LINK-USD_x | LUNA1-USD_x | MATIC-USD_x | ... | ADA-USD_y | ATOM-USD_y | AVAX-USD_y | AXS-USD_y | BTC-USD_y | ETH-USD_y | LINK-USD_y | LUNA1-USD_y | MATIC-USD_y | SOL-USD_y | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 2017-05-09 | NaN | NaN | NaN | NaN | 1755.359985 | NaN | NaN | NaN | NaN | ... | NaN | NaN | NaN | NaN | 1167920000 | NaN | NaN | NaN | NaN | NaN |
| 1 | 2017-05-10 | NaN | NaN | NaN | NaN | 1787.130005 | NaN | NaN | NaN | NaN | ... | NaN | NaN | NaN | NaN | 915723008 | NaN | NaN | NaN | NaN | NaN |
| 2 | 2017-05-11 | NaN | NaN | NaN | NaN | 1848.569946 | NaN | NaN | NaN | NaN | ... | NaN | NaN | NaN | NaN | 799489984 | NaN | NaN | NaN | NaN | NaN |
| 3 | 2017-05-12 | NaN | NaN | NaN | NaN | 1724.239990 | NaN | NaN | NaN | NaN | ... | NaN | NaN | NaN | NaN | 740984000 | NaN | NaN | NaN | NaN | NaN |
| 4 | 2017-05-13 | NaN | NaN | NaN | NaN | 1804.910034 | NaN | NaN | NaN | NaN | ... | NaN | NaN | NaN | NaN | 579635008 | NaN | NaN | NaN | NaN | NaN |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 1821 | 2022-05-04 | 0.896942 | 19.876862 | 67.086105 | 33.363853 | 39698.371094 | 2940.644775 | 12.145610 | 86.172264 | 1.171032 | ... | 1.516023e+09 | 549565214.0 | 8.757237e+08 | 379974515.0 | 36754404490 | 1.818675e+10 | 501855323.0 | 1.941975e+09 | 742971942.0 | 1.428455e+09 |
| 1822 | 2022-05-05 | 0.791152 | 17.853285 | 59.127441 | 28.984409 | 36575.140625 | 2749.213135 | 10.917400 | 82.580406 | 1.064691 | ... | 1.802129e+09 | 614325972.0 | 1.259826e+09 | 488287918.0 | 43106256317 | 2.264293e+10 | 560835165.0 | 2.276428e+09 | 759187845.0 | 1.805979e+09 |
| 1823 | 2022-05-06 | 0.783359 | 17.674110 | 57.034325 | 28.462557 | 36040.921875 | 2694.979736 | 10.799844 | 77.464806 | 1.044133 | ... | 1.312284e+09 | 447936108.0 | 8.872802e+08 | 279097266.0 | 37795577489 | 2.102760e+10 | 507557055.0 | 2.178574e+09 | 704670768.0 | 1.585082e+09 |
| 1824 | 2022-05-07 | 0.761882 | 16.475998 | 55.156693 | 28.750196 | 35501.953125 | 2636.093018 | 10.239905 | 68.249123 | 1.021204 | ... | 8.015589e+08 | 455478758.0 | 5.551183e+08 | 233434007.0 | 24375896406 | 1.336928e+10 | 354478668.0 | 3.054300e+09 | 618880005.0 | 1.139093e+09 |
| 1825 | 2022-05-08 | 0.744362 | 15.785578 | 51.730221 | 30.405958 | 34226.796875 | 2532.283691 | 10.044308 | 64.176682 | 0.979784 | ... | 1.092425e+09 | 412976512.0 | 8.406972e+08 | 509740576.0 | 36945944576 | 2.095508e+10 | 430948928.0 | 5.255014e+09 | 576489152.0 | 1.447528e+09 |
1826 rows × 61 columns
# convert date to pd datetime
df_adj_close['Date'] = pd.to_datetime(df_adj_close['Date'])
df_close['Date'] = pd.to_datetime(df_close['Date'])
df_high['Date'] = pd.to_datetime(df_high['Date'])
df_low['Date'] = pd.to_datetime(df_low['Date'])
df_open['Date'] = pd.to_datetime(df_open['Date'])
df_volume['Date'] = pd.to_datetime(df_volume['Date'])
ADA = df_adj_close[['Date','ADA-USD']]
ADA.columns = ADA.columns.str.replace('ADA-USD', 'adj_close')
ADA['close'] = df_close['ADA-USD']
ADA['high'] = df_high['ADA-USD']
ADA['low'] = df_low['ADA-USD']
ADA['open'] = df_open['ADA-USD']
ADA['volume'] = df_volume['ADA-USD']
ADA = ADA.dropna()
ADA
| Date | adj_close | close | high | low | open | volume | |
|---|---|---|---|---|---|---|---|
| 184 | 2017-11-09 | 0.032053 | 0.032053 | 0.035060 | 0.025006 | 0.025160 | 1.871620e+07 |
| 185 | 2017-11-10 | 0.027119 | 0.027119 | 0.033348 | 0.026451 | 0.032219 | 6.766780e+06 |
| 186 | 2017-11-11 | 0.027437 | 0.027437 | 0.029659 | 0.025684 | 0.026891 | 5.532220e+06 |
| 187 | 2017-11-12 | 0.023977 | 0.023977 | 0.027952 | 0.022591 | 0.027480 | 7.280250e+06 |
| 188 | 2017-11-13 | 0.025808 | 0.025808 | 0.026300 | 0.023495 | 0.024364 | 4.419440e+06 |
| ... | ... | ... | ... | ... | ... | ... | ... |
| 1821 | 2022-05-04 | 0.896942 | 0.896942 | 0.897661 | 0.769638 | 0.771107 | 1.516023e+09 |
| 1822 | 2022-05-05 | 0.791152 | 0.791152 | 0.904111 | 0.778141 | 0.897061 | 1.802129e+09 |
| 1823 | 2022-05-06 | 0.783359 | 0.783359 | 0.798315 | 0.765742 | 0.791065 | 1.312284e+09 |
| 1824 | 2022-05-07 | 0.761882 | 0.761882 | 0.785116 | 0.750657 | 0.783352 | 8.015589e+08 |
| 1825 | 2022-05-08 | 0.744362 | 0.744362 | 0.763704 | 0.731738 | 0.761689 | 1.092425e+09 |
1642 rows × 7 columns
ATOM = df_adj_close[['Date','ATOM-USD']]
ATOM.columns = ATOM.columns.str.replace('ATOM-USD', 'adj_close')
ATOM['close'] = df_close['ATOM-USD']
ATOM['high'] = df_high['ATOM-USD']
ATOM['low'] = df_low['ATOM-USD']
ATOM['open'] = df_open['ATOM-USD']
ATOM['volume'] = df_volume['ATOM-USD']
ATOM = ATOM.dropna()
ATOM
| Date | adj_close | close | high | low | open | volume | |
|---|---|---|---|---|---|---|---|
| 674 | 2019-03-14 | 6.526642 | 6.526642 | 6.639943 | 6.353963 | 6.439715 | 7318172.0 |
| 675 | 2019-03-15 | 7.504351 | 7.504351 | 7.715249 | 6.432468 | 6.633174 | 6057301.0 |
| 676 | 2019-03-16 | 7.383882 | 7.383882 | 8.305615 | 6.694531 | 7.507990 | 3477393.0 |
| 677 | 2019-03-17 | 4.776164 | 4.776164 | 7.357443 | 4.727895 | 7.357443 | 2653565.0 |
| 678 | 2019-03-18 | 5.110341 | 5.110341 | 5.229982 | 4.828242 | 4.828242 | 2567201.0 |
| ... | ... | ... | ... | ... | ... | ... | ... |
| 1821 | 2022-05-04 | 19.876862 | 19.876862 | 19.987272 | 17.563868 | 17.593870 | 549565214.0 |
| 1822 | 2022-05-05 | 17.853285 | 17.853285 | 20.270138 | 17.410774 | 19.871162 | 614325972.0 |
| 1823 | 2022-05-06 | 17.674110 | 17.674110 | 17.950396 | 17.255348 | 17.853285 | 447936108.0 |
| 1824 | 2022-05-07 | 16.475998 | 16.475998 | 17.680393 | 16.186054 | 17.676107 | 455478758.0 |
| 1825 | 2022-05-08 | 15.785578 | 15.785578 | 16.511841 | 15.677500 | 16.511841 | 412976512.0 |
1152 rows × 7 columns
AVAX = df_adj_close[['Date','AVAX-USD']]
AVAX.columns = AVAX.columns.str.replace('AVAX-USD', 'adj_close')
AVAX['close'] = df_close['AVAX-USD']
AVAX['high'] = df_high['AVAX-USD']
AVAX['low'] = df_low['AVAX-USD']
AVAX['open'] = df_open['AVAX-USD']
AVAX['volume'] = df_volume['AVAX-USD']
AVAX = AVAX.dropna()
AVAX
| Date | adj_close | close | high | low | open | volume | |
|---|---|---|---|---|---|---|---|
| 1161 | 2020-07-13 | 4.896294 | 4.896294 | 4.915115 | 4.481499 | 4.613968 | 2.834000e+04 |
| 1162 | 2020-07-14 | 4.986754 | 4.986754 | 5.229564 | 4.762068 | 4.909865 | 3.957000e+03 |
| 1232 | 2020-09-22 | 5.234632 | 5.234632 | 11.463443 | 4.125380 | 4.986754 | 2.880988e+08 |
| 1233 | 2020-09-23 | 4.118469 | 4.118469 | 5.329310 | 3.982604 | 5.321654 | 1.730912e+08 |
| 1234 | 2020-09-24 | 4.566561 | 4.566561 | 4.751878 | 3.539887 | 3.817925 | 9.611096e+07 |
| ... | ... | ... | ... | ... | ... | ... | ... |
| 1821 | 2022-05-04 | 67.086105 | 67.086105 | 67.282066 | 59.498161 | 59.658340 | 8.757237e+08 |
| 1822 | 2022-05-05 | 59.127441 | 59.127441 | 69.349014 | 57.024452 | 67.076157 | 1.259826e+09 |
| 1823 | 2022-05-06 | 57.034325 | 57.034325 | 59.306812 | 55.412495 | 59.121109 | 8.872802e+08 |
| 1824 | 2022-05-07 | 55.156693 | 55.156693 | 57.439198 | 53.625706 | 57.035454 | 5.551183e+08 |
| 1825 | 2022-05-08 | 51.730221 | 51.730221 | 55.253357 | 50.975513 | 55.153175 | 8.406972e+08 |
596 rows × 7 columns
AXS = df_adj_close[['Date','AXS-USD']]
AXS.columns = AXS.columns.str.replace('AXS-USD', 'adj_close')
AXS['close'] = df_close['AXS-USD']
AXS['high'] = df_high['AXS-USD']
AXS['low'] = df_low['AXS-USD']
AXS['open'] = df_open['AXS-USD']
AXS['volume'] = df_volume['AXS-USD']
AXS = AXS.dropna()
AXS
| Date | adj_close | close | high | low | open | volume | |
|---|---|---|---|---|---|---|---|
| 1275 | 2020-11-04 | 0.145949 | 0.145949 | 0.191121 | 0.141809 | 0.179801 | 16344570.0 |
| 1276 | 2020-11-05 | 0.135104 | 0.135104 | 0.150565 | 0.126469 | 0.145951 | 4948417.0 |
| 1277 | 2020-11-06 | 0.143164 | 0.143164 | 0.149547 | 0.123431 | 0.135104 | 3148629.0 |
| 1278 | 2020-11-07 | 0.141056 | 0.141056 | 0.168470 | 0.134455 | 0.143189 | 1987416.0 |
| 1279 | 2020-11-08 | 0.198251 | 0.198251 | 0.239455 | 0.139401 | 0.141021 | 9484360.0 |
| ... | ... | ... | ... | ... | ... | ... | ... |
| 1821 | 2022-05-04 | 33.363853 | 33.363853 | 33.633900 | 28.171825 | 29.114498 | 379974515.0 |
| 1822 | 2022-05-05 | 28.984409 | 28.984409 | 34.753601 | 28.156942 | 33.362663 | 488287918.0 |
| 1823 | 2022-05-06 | 28.462557 | 28.462557 | 29.047382 | 27.466135 | 28.982380 | 279097266.0 |
| 1824 | 2022-05-07 | 28.750196 | 28.750196 | 29.423031 | 27.502634 | 28.464800 | 233434007.0 |
| 1825 | 2022-05-08 | 30.405958 | 30.405958 | 31.376856 | 27.879026 | 28.747194 | 509740576.0 |
551 rows × 7 columns
BTC = df_adj_close[['Date','BTC-USD']]
BTC.columns = BTC.columns.str.replace('BTC-USD', 'adj_close')
BTC['close'] = df_close['BTC-USD']
BTC['high'] = df_high['BTC-USD']
BTC['low'] = df_low['BTC-USD']
BTC['open'] = df_open['BTC-USD']
BTC['volume'] = df_volume['BTC-USD']
BTC = BTC.dropna()
BTC
| Date | adj_close | close | high | low | open | volume | |
|---|---|---|---|---|---|---|---|
| 0 | 2017-05-09 | 1755.359985 | 1755.359985 | 1833.489990 | 1716.300049 | 1723.890015 | 1167920000 |
| 1 | 2017-05-10 | 1787.130005 | 1787.130005 | 1788.439941 | 1719.099976 | 1756.520020 | 915723008 |
| 2 | 2017-05-11 | 1848.569946 | 1848.569946 | 1873.930054 | 1755.349976 | 1780.369995 | 799489984 |
| 3 | 2017-05-12 | 1724.239990 | 1724.239990 | 1856.150024 | 1694.010010 | 1845.760010 | 740984000 |
| 4 | 2017-05-13 | 1804.910034 | 1804.910034 | 1812.989990 | 1651.079956 | 1723.119995 | 579635008 |
| ... | ... | ... | ... | ... | ... | ... | ... |
| 1821 | 2022-05-04 | 39698.371094 | 39698.371094 | 39902.949219 | 37732.058594 | 37748.011719 | 36754404490 |
| 1822 | 2022-05-05 | 36575.140625 | 36575.140625 | 39789.281250 | 35856.515625 | 39695.746094 | 43106256317 |
| 1823 | 2022-05-06 | 36040.921875 | 36040.921875 | 36624.359375 | 35482.132812 | 36573.183594 | 37795577489 |
| 1824 | 2022-05-07 | 35501.953125 | 35501.953125 | 36129.925781 | 34940.824219 | 36042.503906 | 24375896406 |
| 1825 | 2022-05-08 | 34226.796875 | 34226.796875 | 35477.484375 | 33913.957031 | 35473.250000 | 36945944576 |
1826 rows × 7 columns
ETH = df_adj_close[['Date','ETH-USD']]
ETH.columns = ETH.columns.str.replace('ETH-USD', 'adj_close')
ETH['close'] = df_close['ETH-USD']
ETH['high'] = df_high['ETH-USD']
ETH['low'] = df_low['ETH-USD']
ETH['open'] = df_open['ETH-USD']
ETH['volume'] = df_volume['ETH-USD']
ETH = ETH.dropna()
ETH
| Date | adj_close | close | high | low | open | volume | |
|---|---|---|---|---|---|---|---|
| 184 | 2017-11-09 | 320.884003 | 320.884003 | 329.451996 | 307.056000 | 308.644989 | 8.932500e+08 |
| 185 | 2017-11-10 | 299.252991 | 299.252991 | 324.717987 | 294.541992 | 320.670990 | 8.859860e+08 |
| 186 | 2017-11-11 | 314.681000 | 314.681000 | 319.453003 | 298.191986 | 298.585999 | 8.423010e+08 |
| 187 | 2017-11-12 | 307.907990 | 307.907990 | 319.153015 | 298.513000 | 314.690002 | 1.613480e+09 |
| 188 | 2017-11-13 | 316.716003 | 316.716003 | 328.415009 | 307.024994 | 307.024994 | 1.041890e+09 |
| ... | ... | ... | ... | ... | ... | ... | ... |
| 1821 | 2022-05-04 | 2940.644775 | 2940.644775 | 2956.686768 | 2779.273682 | 2783.131104 | 1.818675e+10 |
| 1822 | 2022-05-05 | 2749.213135 | 2749.213135 | 2948.960693 | 2704.916260 | 2940.226562 | 2.264293e+10 |
| 1823 | 2022-05-06 | 2694.979736 | 2694.979736 | 2754.837646 | 2645.335205 | 2748.931641 | 2.102760e+10 |
| 1824 | 2022-05-07 | 2636.093018 | 2636.093018 | 2696.652832 | 2599.523438 | 2694.991943 | 1.336928e+10 |
| 1825 | 2022-05-08 | 2532.283691 | 2532.283691 | 2637.854004 | 2504.324707 | 2637.407227 | 2.095508e+10 |
1642 rows × 7 columns
LINK = df_adj_close[['Date','LINK-USD']]
LINK.columns = LINK.columns.str.replace('LINK-USD', 'adj_close')
LINK['close'] = df_close['LINK-USD']
LINK['high'] = df_high['LINK-USD']
LINK['low'] = df_low['LINK-USD']
LINK['open'] = df_open['LINK-USD']
LINK['volume'] = df_volume['LINK-USD']
LINK = LINK.dropna()
LINK
| Date | adj_close | close | high | low | open | volume | |
|---|---|---|---|---|---|---|---|
| 184 | 2017-11-09 | 0.223969 | 0.223969 | 0.248233 | 0.195411 | 0.216713 | 3347920.0 |
| 185 | 2017-11-10 | 0.187602 | 0.187602 | 0.231280 | 0.180161 | 0.224700 | 2125460.0 |
| 186 | 2017-11-11 | 0.179770 | 0.179770 | 0.197687 | 0.166026 | 0.186398 | 2238980.0 |
| 187 | 2017-11-12 | 0.170898 | 0.170898 | 0.198376 | 0.145948 | 0.179667 | 5455200.0 |
| 188 | 2017-11-13 | 0.183071 | 0.183071 | 0.205014 | 0.168743 | 0.169117 | 2992650.0 |
| ... | ... | ... | ... | ... | ... | ... | ... |
| 1821 | 2022-05-04 | 12.145610 | 12.145610 | 12.146651 | 11.113729 | 11.121224 | 501855323.0 |
| 1822 | 2022-05-05 | 10.917400 | 10.917400 | 12.239243 | 10.738750 | 12.153832 | 560835165.0 |
| 1823 | 2022-05-06 | 10.799844 | 10.799844 | 10.992021 | 10.499268 | 10.916577 | 507557055.0 |
| 1824 | 2022-05-07 | 10.239905 | 10.239905 | 10.817171 | 10.100428 | 10.799866 | 354478668.0 |
| 1825 | 2022-05-08 | 10.044308 | 10.044308 | 10.344585 | 9.925760 | 10.254740 | 430948928.0 |
1642 rows × 7 columns
LUNA1 = df_adj_close[['Date','LUNA1-USD']]
LUNA1.columns = LUNA1.columns.str.replace('LUNA1-USD', 'adj_close')
LUNA1['close'] = df_close['LUNA1-USD']
LUNA1['high'] = df_high['LUNA1-USD']
LUNA1['low'] = df_low['LUNA1-USD']
LUNA1['open'] = df_open['LUNA1-USD']
LUNA1['volume'] = df_volume['LUNA1-USD']
LUNA1 = LUNA1.dropna()
LUNA1
| Date | adj_close | close | high | low | open | volume | |
|---|---|---|---|---|---|---|---|
| 808 | 2019-07-26 | 1.327436 | 1.327436 | 1.833167 | 1.261695 | 1.704222 | 1.208858e+07 |
| 809 | 2019-07-27 | 1.310566 | 1.310566 | 1.402898 | 1.221938 | 1.327436 | 6.033446e+06 |
| 810 | 2019-07-28 | 1.272989 | 1.272989 | 1.368595 | 1.236858 | 1.310566 | 1.643709e+06 |
| 811 | 2019-07-29 | 1.294661 | 1.294661 | 1.375941 | 1.175443 | 1.262270 | 3.966802e+06 |
| 812 | 2019-07-30 | 1.294193 | 1.294193 | 1.374333 | 1.266484 | 1.294435 | 1.820705e+06 |
| ... | ... | ... | ... | ... | ... | ... | ... |
| 1821 | 2022-05-04 | 86.172264 | 86.172264 | 87.956352 | 82.267265 | 82.584396 | 1.941975e+09 |
| 1822 | 2022-05-05 | 82.580406 | 82.580406 | 87.777588 | 79.330872 | 86.159637 | 2.276428e+09 |
| 1823 | 2022-05-06 | 77.464806 | 77.464806 | 82.936325 | 77.432007 | 82.551933 | 2.178574e+09 |
| 1824 | 2022-05-07 | 68.249123 | 68.249123 | 77.494347 | 63.838245 | 77.465630 | 3.054300e+09 |
| 1825 | 2022-05-08 | 64.176682 | 64.176682 | 68.271729 | 59.578342 | 68.271729 | 5.255014e+09 |
1018 rows × 7 columns
MATIC = df_adj_close[['Date','MATIC-USD']]
MATIC.columns = MATIC.columns.str.replace('MATIC-USD', 'adj_close')
MATIC['close'] = df_close['MATIC-USD']
MATIC['high'] = df_high['MATIC-USD']
MATIC['low'] = df_low['MATIC-USD']
MATIC['open'] = df_open['MATIC-USD']
MATIC['volume'] = df_volume['MATIC-USD']
MATIC = MATIC.dropna()
MATIC
| Date | adj_close | close | high | low | open | volume | |
|---|---|---|---|---|---|---|---|
| 719 | 2019-04-28 | 0.004421 | 0.004421 | 0.004545 | 0.004317 | 0.004521 | 8408136.0 |
| 720 | 2019-04-29 | 0.003471 | 0.003471 | 0.004492 | 0.003471 | 0.004418 | 8267044.0 |
| 721 | 2019-04-30 | 0.004478 | 0.004478 | 0.005078 | 0.003458 | 0.003462 | 25072706.0 |
| 722 | 2019-05-01 | 0.004374 | 0.004374 | 0.004673 | 0.004071 | 0.004440 | 10567352.0 |
| 723 | 2019-05-02 | 0.004198 | 0.004198 | 0.004700 | 0.004096 | 0.004366 | 6714908.0 |
| ... | ... | ... | ... | ... | ... | ... | ... |
| 1821 | 2022-05-04 | 1.171032 | 1.171032 | 1.171143 | 1.073876 | 1.075928 | 742971942.0 |
| 1822 | 2022-05-05 | 1.064691 | 1.064691 | 1.185085 | 1.035494 | 1.170986 | 759187845.0 |
| 1823 | 2022-05-06 | 1.044133 | 1.044133 | 1.075262 | 1.022339 | 1.064479 | 704670768.0 |
| 1824 | 2022-05-07 | 1.021204 | 1.021204 | 1.064007 | 1.000354 | 1.044149 | 618880005.0 |
| 1825 | 2022-05-08 | 0.979784 | 0.979784 | 1.026015 | 0.966227 | 1.024481 | 576489152.0 |
1107 rows × 7 columns
SOL = df_adj_close[['Date','SOL-USD']]
SOL.columns = SOL.columns.str.replace('SOL-USD', 'adj_close')
SOL['close'] = df_close['SOL-USD']
SOL['high'] = df_high['SOL-USD']
SOL['low'] = df_low['SOL-USD']
SOL['open'] = df_open['SOL-USD']
SOL['volume'] = df_volume['SOL-USD']
SOL = SOL.dropna()
SOL
| Date | adj_close | close | high | low | open | volume | |
|---|---|---|---|---|---|---|---|
| 1067 | 2020-04-10 | 0.951054 | 0.951054 | 1.313487 | 0.694187 | 0.832005 | 8.736428e+07 |
| 1068 | 2020-04-11 | 0.776819 | 0.776819 | 1.049073 | 0.765020 | 0.951054 | 4.386244e+07 |
| 1069 | 2020-04-12 | 0.882507 | 0.882507 | 0.956670 | 0.762426 | 0.785448 | 3.873690e+07 |
| 1070 | 2020-04-13 | 0.777832 | 0.777832 | 0.891603 | 0.773976 | 0.890760 | 1.821128e+07 |
| 1071 | 2020-04-14 | 0.661925 | 0.661925 | 0.796472 | 0.628169 | 0.777832 | 1.674761e+07 |
| ... | ... | ... | ... | ... | ... | ... | ... |
| 1821 | 2022-05-04 | 92.770851 | 92.770851 | 92.937195 | 85.728065 | 85.841728 | 1.428455e+09 |
| 1822 | 2022-05-05 | 84.596024 | 84.596024 | 95.032822 | 81.834869 | 92.769791 | 1.805979e+09 |
| 1823 | 2022-05-06 | 81.764107 | 81.764107 | 84.646935 | 80.468613 | 84.588493 | 1.585082e+09 |
| 1824 | 2022-05-07 | 78.983421 | 78.983421 | 82.180786 | 77.883232 | 81.766670 | 1.139093e+09 |
| 1825 | 2022-05-08 | 75.536499 | 75.536499 | 79.194817 | 74.570267 | 79.022034 | 1.447528e+09 |
759 rows × 7 columns
def CandleMaker(df):
fig = go.Figure(data=[go.Candlestick(x=df['Date'],
open=df['open'],
high=df['high'],
low=df['low'],
close=df['close'])])
fig.show()
CandleMaker(ADA)
CandleMaker(ATOM)
CandleMaker(AVAX)
CandleMaker(AXS)
CandleMaker(BTC)
CandleMaker(ETH)
CandleMaker(LINK)
CandleMaker(LUNA1)
CandleMaker(MATIC)
CandleMaker(SOL)
fig = px.line(df_high, x="Date", y=df_high.columns,
hover_data={"Date"},
title='Daliy High price of Ten Cryptocurrenies')
fig.update_xaxes(rangeslider_visible=True)
fig.update_yaxes(type="log")
fig.show()
fig = px.line(df_high.dropna(), x="Date", y=df_high.columns,
hover_data={"Date"},
title='Daliy High price of Ten Cryptocurrenies since the last one in the market')
fig.update_xaxes(rangeslider_visible=True)
fig.update_yaxes(type="log")
fig.show()
fig = px.line(df_volume, x="Date", y=df_high.columns,
hover_data={"Date"},
title='Daliy Volume of Ten Cryptocurrenies')
fig.update_xaxes(rangeslider_visible=True)
fig.update_yaxes(type="log")
fig.show()
fig = make_subplots(
rows=10, cols=1,
shared_xaxes=True,
vertical_spacing=0.03,
specs=[[{"type": "scatter"}],
[{"type": "scatter"}],
[{"type": "scatter"}],
[{"type": "scatter"}],
[{"type": "scatter"}],
[{"type": "scatter"}],
[{"type": "scatter"}],
[{"type": "scatter"}],
[{"type": "scatter"}],
[{"type": "scatter"}]]
)
fig.add_trace(go.Scatter(x=df_high["Date"],y=df_high["ADA-USD"],mode="lines",name="ADA"),
row=1, col=1)
fig.add_trace(go.Scatter(x=df_high["Date"],y=df_high["ATOM-USD"],mode="lines",name="ATOM"),
row=2, col=1)
fig.add_trace(go.Scatter(x=df_high["Date"],y=df_high["AVAX-USD"],mode="lines",name="AVAX"),
row=3, col=1)
fig.add_trace(go.Scatter(x=df_high["Date"],y=df_high["AXS-USD"],mode="lines",name="AXS"),
row=4, col=1)
fig.add_trace(go.Scatter(x=df_high["Date"],y=df_high["BTC-USD"],mode="lines",name="BTC"),
row=5, col=1)
fig.add_trace(go.Scatter(x=df_high["Date"],y=df_high["ETH-USD"],mode="lines",name="ETH"),
row=6, col=1)
fig.add_trace(go.Scatter(x=df_high["Date"],y=df_high["LINK-USD"],mode="lines",name="LINK"),
row=7, col=1)
fig.add_trace(go.Scatter(x=df_high["Date"],y=df_high["LUNA1-USD"],mode="lines",name="LUNA1"),
row=8, col=1)
fig.add_trace(go.Scatter(x=df_high["Date"],y=df_high["MATIC-USD"],mode="lines",name="MATIC"),
row=9, col=1)
fig.add_trace(go.Scatter(x=df_high["Date"],y=df_high["SOL-USD"],mode="lines",name="SOL"),
row=10, col=1)
fig.update_layout(
height=800,
showlegend=False,
title_text="Daliy High price of Ten Cryptocurrenies subplots",
)
fig.show()
fig = make_subplots(
rows=10, cols=1,
shared_xaxes=True,
vertical_spacing=0.03,
specs=[[{"type": "scatter"}],
[{"type": "scatter"}],
[{"type": "scatter"}],
[{"type": "scatter"}],
[{"type": "scatter"}],
[{"type": "scatter"}],
[{"type": "scatter"}],
[{"type": "scatter"}],
[{"type": "scatter"}],
[{"type": "scatter"}]]
)
fig.add_trace(go.Scatter(x=df_volume["Date"],y=df_volume["ADA-USD"],mode="lines",name="ADA"),
row=1, col=1)
fig.add_trace(go.Scatter(x=df_volume["Date"],y=df_volume["ATOM-USD"],mode="lines",name="ATOM"),
row=2, col=1)
fig.add_trace(go.Scatter(x=df_volume["Date"],y=df_volume["AVAX-USD"],mode="lines",name="AVAX"),
row=3, col=1)
fig.add_trace(go.Scatter(x=df_volume["Date"],y=df_volume["AXS-USD"],mode="lines",name="AXS"),
row=4, col=1)
fig.add_trace(go.Scatter(x=df_volume["Date"],y=df_volume["BTC-USD"],mode="lines",name="BTC"),
row=5, col=1)
fig.add_trace(go.Scatter(x=df_volume["Date"],y=df_volume["ETH-USD"],mode="lines",name="ETH"),
row=6, col=1)
fig.add_trace(go.Scatter(x=df_volume["Date"],y=df_volume["LINK-USD"],mode="lines",name="LINK"),
row=7, col=1)
fig.add_trace(go.Scatter(x=df_volume["Date"],y=df_volume["LUNA1-USD"],mode="lines",name="LUNA1"),
row=8, col=1)
fig.add_trace(go.Scatter(x=df_volume["Date"],y=df_volume["MATIC-USD"],mode="lines",name="MATIC"),
row=9, col=1)
fig.add_trace(go.Scatter(x=df_volume["Date"],y=df_volume["SOL-USD"],mode="lines",name="SOL"),
row=10, col=1)
fig.update_layout(
height=1500,
showlegend=False,
title_text="Daliy Volume of Ten Cryptocurrenies subplots",
)
fig.show()
df_dif_high_low = df_high.loc[:, df_high.columns != 'Date']-df_low.loc[:, df_low.columns != 'Date']
fig = make_subplots(
rows=2, cols=5,
vertical_spacing=0.03,
specs=[[{"type": "box"}, {"type": "box"},{"type": "box"}, {"type": "box"},{"type": "box"}],
[{"type": "box"}, {"type": "box"},{"type": "box"}, {"type": "box"},{"type": "box"}]])
fig.add_trace(go.Box(y=df_dif_high_low["ADA-USD"],name="ADA"),
row=1, col=1)
fig.add_trace(go.Box(y=df_dif_high_low["ATOM-USD"],name="ATOM"),
row=1, col=2)
fig.add_trace(go.Box(y=df_dif_high_low["AVAX-USD"],name="AVAX"),
row=1, col=3)
fig.add_trace(go.Box(y=df_dif_high_low["AXS-USD"],name="AXS"),
row=1, col=4)
fig.add_trace(go.Box(y=df_dif_high_low["BTC-USD"],name="BTC"),
row=1, col=5)
fig.add_trace(go.Box(y=df_dif_high_low["ETH-USD"],name="ETH"),
row=2, col=1)
fig.add_trace(go.Box(y=df_dif_high_low["LINK-USD"],name="LINK"),
row=2, col=2)
fig.add_trace(go.Box(y=df_dif_high_low["LUNA1-USD"],name="LUNA1"),
row=2, col=3)
fig.add_trace(go.Box(y=df_dif_high_low["MATIC-USD"],name="MATIC"),
row=2, col=4)
fig.add_trace(go.Box(y=df_dif_high_low["SOL-USD"],name="SOL"),
row=2, col=5)
fig.update_layout(height=1000, width=1000, title_text="Boxplots of the daily diffrence between Value high and low")
df_dif_open_close = df_close.loc[:, df_close.columns != 'Date']-df_open.loc[:, df_open.columns != 'Date']
fig = make_subplots(
rows=2, cols=5,
vertical_spacing=0.03,
specs=[[{"type": "box"}, {"type": "box"},{"type": "box"}, {"type": "box"},{"type": "box"}],
[{"type": "box"}, {"type": "box"},{"type": "box"}, {"type": "box"},{"type": "box"}]])
fig.add_trace(go.Box(y=df_dif_open_close["ADA-USD"],name="ADA"),
row=1, col=1)
fig.add_trace(go.Box(y=df_dif_open_close["ATOM-USD"],name="ATOM"),
row=1, col=2)
fig.add_trace(go.Box(y=df_dif_open_close["AVAX-USD"],name="AVAX"),
row=1, col=3)
fig.add_trace(go.Box(y=df_dif_open_close["AXS-USD"],name="AXS"),
row=1, col=4)
fig.add_trace(go.Box(y=df_dif_open_close["BTC-USD"],name="BTC"),
row=1, col=5)
fig.add_trace(go.Box(y=df_dif_open_close["ETH-USD"],name="ETH"),
row=2, col=1)
fig.add_trace(go.Box(y=df_dif_open_close["LINK-USD"],name="LINK"),
row=2, col=2)
fig.add_trace(go.Box(y=df_dif_open_close["LUNA1-USD"],name="LUNA1"),
row=2, col=3)
fig.add_trace(go.Box(y=df_dif_open_close["MATIC-USD"],name="MATIC"),
row=2, col=4)
fig.add_trace(go.Box(y=df_dif_open_close["SOL-USD"],name="SOL"),
row=2, col=5)
fig.update_layout(height=1000, width=1000, title_text="Boxplots of the daily diffrence between Value Open and close")
df_dif_adjc_close = df_close.loc[:, df_close.columns != 'Date']-df_adj_close.loc[:, df_adj_close.columns != 'Date']
fig = make_subplots(
rows=2, cols=5,
vertical_spacing=0.03,
specs=[[{"type": "box"}, {"type": "box"},{"type": "box"}, {"type": "box"},{"type": "box"}],
[{"type": "box"}, {"type": "box"},{"type": "box"}, {"type": "box"},{"type": "box"}]])
fig.add_trace(go.Box(y=df_dif_adjc_close["ADA-USD"],name="ADA"),
row=1, col=1)
fig.add_trace(go.Box(y=df_dif_adjc_close["ATOM-USD"],name="ATOM"),
row=1, col=2)
fig.add_trace(go.Box(y=df_dif_adjc_close["AVAX-USD"],name="AVAX"),
row=1, col=3)
fig.add_trace(go.Box(y=df_dif_adjc_close["AXS-USD"],name="AXS"),
row=1, col=4)
fig.add_trace(go.Box(y=df_dif_adjc_close["BTC-USD"],name="BTC"),
row=1, col=5)
fig.add_trace(go.Box(y=df_dif_adjc_close["ETH-USD"],name="ETH"),
row=2, col=1)
fig.add_trace(go.Box(y=df_dif_adjc_close["LINK-USD"],name="LINK"),
row=2, col=2)
fig.add_trace(go.Box(y=df_dif_adjc_close["LUNA1-USD"],name="LUNA1"),
row=2, col=3)
fig.add_trace(go.Box(y=df_dif_adjc_close["MATIC-USD"],name="MATIC"),
row=2, col=4)
fig.add_trace(go.Box(y=df_dif_adjc_close["SOL-USD"],name="SOL"),
row=2, col=5)
fig.update_layout(height=400, width=1000, title_text="Boxplots of the daily diffrence between Value adjust close and close")
def get_df_name(df):
name =[x for x in globals() if globals()[x] is df][0]
return name
def Volume_Candlesticks_maker(df):
# Create figure with secondary y-axis
fig = make_subplots(specs=[[{"secondary_y": True}]])
# Add traces
fig.add_trace(
go.Scatter( x=df['Date'],
y=df['volume'],
name='volume'),
secondary_y=False,
)
fig.add_trace(
go.Candlestick(x=df['Date'],
open=df['open'],
high=df['high'],
low=df['low'],
close=df['close'],
name=get_df_name(df)),
secondary_y=True,
)
# Add figure title
fig.update_layout(
title_text=get_df_name(df)+" Volume and Candlesticks"
)
# Set x-axis title
fig.update_xaxes(title_text="Date")
# Set y-axes titles
fig.update_yaxes(title_text="<b>volume</b> yaxis ", secondary_y=False)
fig.update_yaxes(title_text="<b>Candlestick</b> yaxis ", secondary_y=True)
fig.show()
Volume_Candlesticks_maker(ADA)
Volume_Candlesticks_maker(ATOM)
Volume_Candlesticks_maker(AVAX)
Volume_Candlesticks_maker(AXS)
Volume_Candlesticks_maker(BTC)
Volume_Candlesticks_maker(ETH)
Volume_Candlesticks_maker(LINK)
Volume_Candlesticks_maker(LUNA1)
Volume_Candlesticks_maker(MATIC)
Volume_Candlesticks_maker(SOL)
# select data since 2021-01-01, drop adjust close, change the name of columns
def selectdata(df):
mask = (df['Date'] >= '2021-01-01')
df = df.loc[mask]
df = df.loc[:, df.columns != 'adj_close']
return df
ADA = selectdata(ADA)
ATOM = selectdata(ATOM)
AVAX = selectdata(AVAX)
AXS = selectdata(AXS)
BTC = selectdata(BTC)
ETH = selectdata(ETH)
LINK = selectdata(LINK)
LUNA1 = selectdata(LUNA1)
MATIC = selectdata(MATIC)
SOL = selectdata(SOL)
def renamecolumns(df):
df.columns =[df.columns[0]]+[str(get_df_name(df).replace("_copy", ""))+'_'+i for i in df.columns[1:]]
return df
ADA_copy=ADA.copy()
renamecolumns(ADA_copy)
ATOM_copy=ATOM.copy()
renamecolumns(ATOM_copy)
AVAX_copy=AVAX.copy()
renamecolumns(AVAX_copy)
AXS_copy=AXS.copy()
renamecolumns(AXS_copy)
BTC_copy=BTC.copy()
renamecolumns(BTC_copy)
ETH_copy=ETH.copy()
renamecolumns(ETH_copy)
LINK_copy=LINK.copy()
renamecolumns(LINK_copy)
LUNA1_copy=LUNA1.copy()
renamecolumns(LUNA1_copy)
MATIC_copy=MATIC.copy()
renamecolumns(MATIC_copy)
SOL_copy=SOL.copy()
renamecolumns(SOL_copy)
| Date | SOL_close | SOL_high | SOL_low | SOL_open | SOL_volume | |
|---|---|---|---|---|---|---|
| 1333 | 2021-01-01 | 1.842084 | 1.859656 | 1.502038 | 1.509775 | 2.572255e+07 |
| 1334 | 2021-01-02 | 1.799275 | 1.989295 | 1.721482 | 1.845586 | 3.167106e+07 |
| 1335 | 2021-01-03 | 2.161752 | 2.364981 | 1.799902 | 1.799902 | 5.507342e+07 |
| 1336 | 2021-01-04 | 2.485097 | 2.485097 | 1.876342 | 2.162412 | 5.995540e+07 |
| 1337 | 2021-01-05 | 2.157217 | 2.502616 | 2.077742 | 2.490982 | 5.055521e+07 |
| ... | ... | ... | ... | ... | ... | ... |
| 1821 | 2022-05-04 | 92.770851 | 92.937195 | 85.728065 | 85.841728 | 1.428455e+09 |
| 1822 | 2022-05-05 | 84.596024 | 95.032822 | 81.834869 | 92.769791 | 1.805979e+09 |
| 1823 | 2022-05-06 | 81.764107 | 84.646935 | 80.468613 | 84.588493 | 1.585082e+09 |
| 1824 | 2022-05-07 | 78.983421 | 82.180786 | 77.883232 | 81.766670 | 1.139093e+09 |
| 1825 | 2022-05-08 | 75.536499 | 79.194817 | 74.570267 | 79.022034 | 1.447528e+09 |
493 rows × 6 columns
# compile the list of dataframes you want to merge
data_frames = [ADA_copy, ATOM_copy, AVAX_copy, AXS_copy, BTC_copy, ETH_copy, LINK_copy, LUNA1_copy, MATIC_copy, SOL_copy]
df_all = reduce(lambda left,right: pd.merge(left,right,on=['Date'],
how='outer'), data_frames)
df_all.head(3)
| Date | ADA_close | ADA_high | ADA_low | ADA_open | ADA_volume | ATOM_close | ATOM_high | ATOM_low | ATOM_open | ... | MATIC_close | MATIC_high | MATIC_low | MATIC_open | MATIC_volume | SOL_close | SOL_high | SOL_low | SOL_open | SOL_volume | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 2021-01-01 | 0.175350 | 0.184246 | 0.172022 | 0.181382 | 1.122218e+09 | 5.868556 | 6.506998 | 5.652401 | 6.490297 | ... | 0.017812 | 0.018774 | 0.017454 | 0.017633 | 9798566.0 | 1.842084 | 1.859656 | 1.502038 | 1.509775 | 25722549.0 |
| 1 | 2021-01-02 | 0.177423 | 0.184253 | 0.169233 | 0.175359 | 1.408850e+09 | 5.414613 | 5.882211 | 5.319140 | 5.869282 | ... | 0.019043 | 0.019600 | 0.017331 | 0.017812 | 17374970.0 | 1.799275 | 1.989295 | 1.721482 | 1.845586 | 31671064.0 |
| 2 | 2021-01-03 | 0.204995 | 0.208679 | 0.173376 | 0.177382 | 2.303858e+09 | 5.813898 | 5.900645 | 5.301713 | 5.416301 | ... | 0.019975 | 0.020570 | 0.018910 | 0.019053 | 17908526.0 | 2.161752 | 2.364981 | 1.799902 | 1.799902 | 55073422.0 |
3 rows × 51 columns
close_off_high represents the gap between the closing price and price high for that day, where values of -1 and 1 mean the closing price was equal to the daily low or daily high, respectively. The volatility columns are simply the difference between high and low price divided by the opening price.
for coins in ['ADA_', 'ATOM_','AVAX_', 'AXS_','BTC_', 'ETH_','LINK_', 'LUNA1_','MATIC_', 'SOL_']:
kwargs = {coins+'close_off_high': lambda x: (x[coins+'high']- x[coins+'close'])/(x[coins+'high']-x[coins+'low']),
coins+'volatility': lambda x: (x[coins+'high']- x[coins+'low'])/(x[coins+'open']),
coins+'day_diff': lambda x: (x[coins+'close']-x[coins+'open'])/x[coins+'open']}
df_all = df_all.assign(**kwargs)
df_all.columns
Index(['Date', 'ADA_close', 'ADA_high', 'ADA_low', 'ADA_open', 'ADA_volume',
'ATOM_close', 'ATOM_high', 'ATOM_low', 'ATOM_open', 'ATOM_volume',
'AVAX_close', 'AVAX_high', 'AVAX_low', 'AVAX_open', 'AVAX_volume',
'AXS_close', 'AXS_high', 'AXS_low', 'AXS_open', 'AXS_volume',
'BTC_close', 'BTC_high', 'BTC_low', 'BTC_open', 'BTC_volume',
'ETH_close', 'ETH_high', 'ETH_low', 'ETH_open', 'ETH_volume',
'LINK_close', 'LINK_high', 'LINK_low', 'LINK_open', 'LINK_volume',
'LUNA1_close', 'LUNA1_high', 'LUNA1_low', 'LUNA1_open', 'LUNA1_volume',
'MATIC_close', 'MATIC_high', 'MATIC_low', 'MATIC_open', 'MATIC_volume',
'SOL_close', 'SOL_high', 'SOL_low', 'SOL_open', 'SOL_volume',
'ADA_close_off_high', 'ADA_volatility', 'ADA_day_diff',
'ATOM_close_off_high', 'ATOM_volatility', 'ATOM_day_diff',
'AVAX_close_off_high', 'AVAX_volatility', 'AVAX_day_diff',
'AXS_close_off_high', 'AXS_volatility', 'AXS_day_diff',
'BTC_close_off_high', 'BTC_volatility', 'BTC_day_diff',
'ETH_close_off_high', 'ETH_volatility', 'ETH_day_diff',
'LINK_close_off_high', 'LINK_volatility', 'LINK_day_diff',
'LUNA1_close_off_high', 'LUNA1_volatility', 'LUNA1_day_diff',
'MATIC_close_off_high', 'MATIC_volatility', 'MATIC_day_diff',
'SOL_close_off_high', 'SOL_volatility', 'SOL_day_diff'],
dtype='object')
df_all['day'] = df_all['Date'].dt.day
df_all['month'] = df_all['Date'].dt.month
df_all['weekday'] = df_all['Date'].dt.weekday
df_all.head(3)
| Date | ADA_close | ADA_high | ADA_low | ADA_open | ADA_volume | ATOM_close | ATOM_high | ATOM_low | ATOM_open | ... | LUNA1_day_diff | MATIC_close_off_high | MATIC_volatility | MATIC_day_diff | SOL_close_off_high | SOL_volatility | SOL_day_diff | day | month | weekday | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 2021-01-01 | 0.175350 | 0.184246 | 0.172022 | 0.181382 | 1.122218e+09 | 5.868556 | 6.506998 | 5.652401 | 6.490297 | ... | -0.005289 | 0.728788 | 0.074860 | 0.010151 | 0.049136 | 0.236868 | 0.220105 | 1 | 1 | 4 |
| 1 | 2021-01-02 | 0.177423 | 0.184253 | 0.169233 | 0.175359 | 1.408850e+09 | 5.414613 | 5.882211 | 5.319140 | 5.869282 | ... | -0.027640 | 0.245483 | 0.127386 | 0.069111 | 0.709525 | 0.145110 | -0.025093 | 2 | 1 | 5 |
| 2 | 2021-01-03 | 0.204995 | 0.208679 | 0.173376 | 0.177382 | 2.303858e+09 | 5.813898 | 5.900645 | 5.301713 | 5.416301 | ... | 0.047980 | 0.358435 | 0.087125 | 0.048391 | 0.359647 | 0.313950 | 0.201039 | 3 | 1 | 6 |
3 rows × 84 columns
from sklearn.model_selection import TimeSeriesSplit
tscv = TimeSeriesSplit(n_splits=5,test_size=7,)
BTC = BTC.reset_index(drop=True)
tscv.split(BTC)
<generator object TimeSeriesSplit.split at 0x0000023F023F8120>
#Use BTC coin to test
BTC_train=BTC[0:-7]
BTC_test=BTC[-7:]
BTC_train.index = BTC_train.Date
BTC_test.index = BTC_test.Date
#Plotting data
BTC_train.high.plot(figsize=(15,8), title= 'Daily highprice', fontsize=14)
BTC_test.high.plot(figsize=(15,8), title= 'Daily highprice', fontsize=14)
plt.show()
Avg_rms=[]
for train_index, test_index in tscv.split(BTC):
BTC_train, BTC_test = BTC.loc[train_index], BTC.loc[test_index]
dd= np.asarray(BTC_train.high)
y_hat = BTC_test.copy()
y_hat['naive'] = dd[len(dd)-1]
plt.figure(figsize=(12,8))
plt.plot(BTC_train.index, BTC_train['high'], label='Train')
plt.plot(BTC_test.index,BTC_test['high'], label='Test')
plt.plot(y_hat.index,y_hat['naive'], label='Naive Forecast')
plt.legend(loc='best')
plt.title("Naive Forecast")
plt.show()
rms = sqrt(mean_squared_error(BTC_test.high, y_hat.naive))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
2999.7605664405705
2360.8267742856406
1205.6036969059758
773.7626385422295
1826.51959680582 average rmse score is: 1833.2946545960472
Avg_rms=[]
for train_index, test_index in tscv.split(BTC):
BTC_train, BTC_test = BTC.loc[train_index], BTC.loc[test_index]
y_hat_avg = BTC_test.copy()
y_hat_avg['avg_forecast'] = BTC_train['high'].mean()
plt.figure(figsize=(16,8))
plt.plot(BTC_train['high'], label='Train')
plt.plot(BTC_test['high'], label='Test')
plt.plot(y_hat_avg['avg_forecast'], label='Average Forecast')
plt.legend(loc='best')
plt.show()
rms = sqrt(mean_squared_error(BTC_test.high, y_hat_avg.avg_forecast))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
3123.6328361488345
6344.521152312024
6234.921882010013
7536.325664696583
9334.519898325081 average rmse score is: 6514.784286698507
Avg_rms=[]
for train_index, test_index in tscv.split(BTC):
BTC_train, BTC_test = BTC.loc[train_index], BTC.loc[test_index]
y_hat_avg = BTC_test.copy()
y_hat_avg['moving_avg_forecast'] = BTC_train['high'].rolling(14).mean().iloc[-1]
plt.figure(figsize=(16,8))
plt.plot(BTC_train['high'], label='Train')
plt.plot(BTC_test['high'], label='Test')
plt.plot(y_hat_avg['moving_avg_forecast'], label='Moving Average Forecast')
plt.legend(loc='best')
plt.show()
rms = sqrt(mean_squared_error(BTC_test.high, y_hat_avg.moving_avg_forecast))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
1861.8127239063767
5049.83251378449
2045.187189806388
1600.0124431098986
3028.6543700795014 average rmse score is: 2717.099848137331
Avg_rms=[]
for train_index, test_index in tscv.split(BTC):
BTC_train, BTC_test = BTC.loc[train_index], BTC.loc[test_index]
y_hat_avg = BTC_test.copy()
fit2 = SimpleExpSmoothing(np.asarray(BTC_train['high'])).fit(smoothing_level=0.6,optimized=False)
y_hat_avg['SES'] = fit2.forecast(len(BTC_test))
plt.figure(figsize=(16,8))
plt.plot(BTC_train['high'], label='Train')
plt.plot(BTC_test['high'], label='Test')
plt.plot(y_hat_avg['SES'], label='SES')
plt.legend(loc='best')
plt.show()
rms = sqrt(mean_squared_error(BTC_test.high, y_hat_avg.SES))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
2899.840743408813
2359.4082397790316
1169.1986060214524
858.4079424318037
1933.6876512840665 average rmse score is: 1844.1086365850333
Avg_rms=[]
for train_index, test_index in tscv.split(BTC):
BTC_train, BTC_test = BTC.loc[train_index], BTC.loc[test_index]
y_hat_avg = BTC_test.copy()
fit1 = Holt(np.asarray(BTC_train['high'])).fit(smoothing_level = 0.3,smoothing_slope = 0.1)
y_hat_avg['Holt_linear'] = fit1.forecast(len(BTC_test))
plt.figure(figsize=(16,8))
plt.plot(BTC_train['high'], label='Train')
plt.plot(BTC_test['high'], label='Test')
plt.plot(y_hat_avg['Holt_linear'], label='Holt_linear')
plt.legend(loc='best')
plt.show()
rms = sqrt(mean_squared_error(BTC_test.high, y_hat_avg.Holt_linear))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
4955.823119755983
2703.4826936540735
2225.393319028871
552.6283822459842
1418.6394724297238 average rmse score is: 2371.1933974229273
Avg_rms=[]
for train_index, test_index in tscv.split(BTC):
BTC_train, BTC_test = BTC.loc[train_index], BTC.loc[test_index]
y_hat_avg = BTC_test.copy()
fit1 = ExponentialSmoothing(np.asarray(BTC_train['high']) ,seasonal_periods=7 ,trend='add', seasonal='add',).fit()
y_hat_avg['Holt_Winter'] = fit1.forecast(len(BTC_test))
plt.figure(figsize=(16,8))
plt.plot(BTC_train['high'], label='Train')
plt.plot(BTC_test['high'], label='Test')
plt.plot(y_hat_avg['Holt_Winter'], label='Holt_Winter')
plt.legend(loc='best')
plt.show()
rms = sqrt(mean_squared_error(BTC_test.high, y_hat_avg.Holt_Winter))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
4055.8704136779174
2659.6991876914553
979.2357243640067
653.9406017703092
1410.2524254326497 average rmse score is: 1951.7996705872677
Avg_rms=[]
for train_index, test_index in tscv.split(BTC):
BTC_train, BTC_test = BTC.loc[train_index], BTC.loc[test_index]
BTC_train.index=BTC_train.Date
BTC_test.index=BTC_test.Date
y_hat_avg = BTC_test.copy()
fit1 = sm.tsa.statespace.SARIMAX(BTC_train.high,seasonal_order=(0,1,1,7)).fit()
y_hat_avg['SARIMA'] = fit1.predict(start=BTC_test.Date[0], end=BTC_test.Date[-1], dynamic=True)
plt.figure(figsize=(16,8))
plt.plot(BTC_train['high'], label='Train')
plt.plot(BTC_test['high'], label='Test')
plt.plot(y_hat_avg['SARIMA'], label='SARIMA')
plt.legend(loc='best')
plt.show()
rms = sqrt(mean_squared_error(BTC_test.high, y_hat_avg.SARIMA))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
2867.511525862575
2385.765823296961
1092.9784610417405
710.1879904763464
1821.416754255386 average rmse score is: 1775.572110986602
class BlockingTimeSeriesSplit():
def __init__(self, n_splits):
self.n_splits = n_splits
def get_n_splits(self, X, y, groups):
return self.n_splits
def split(self, X, y=None, groups=None):
n_samples = len(X)
k_fold_size = n_samples // self.n_splits
indices = np.arange(n_samples)
margin = 0
for i in range(self.n_splits):
start = i * k_fold_size
stop = start + k_fold_size
last7 = int(0.93 * (stop - start)) + start
yield indices[start: last7], indices[last7 + margin: stop]
btscv = BlockingTimeSeriesSplit(n_splits=5)
btscv.split(BTC)
for train_index, test_index in btscv.split(BTC):
print("TRAIN:", train_index, "TEST:", test_index)
TRAIN: [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90] TEST: [91 92 93 94 95 96 97] TRAIN: [ 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188] TEST: [189 190 191 192 193 194 195] TRAIN: [196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286] TEST: [287 288 289 290 291 292 293] TRAIN: [294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384] TEST: [385 386 387 388 389 390 391] TRAIN: [392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482] TEST: [483 484 485 486 487 488 489]
Avg_rms=[]
for train_index, test_index in btscv.split(BTC):
BTC_train, BTC_test = BTC.loc[train_index], BTC.loc[test_index]
dd= np.asarray(BTC_train.high)
y_hat = BTC_test.copy()
y_hat['naive'] = dd[len(dd)-1]
plt.figure(figsize=(12,8))
plt.plot(BTC_train.index, BTC_train['high'], label='Train')
plt.plot(BTC_test.index,BTC_test['high'], label='Test')
plt.plot(y_hat.index,y_hat['naive'], label='Naive Forecast')
plt.legend(loc='best')
plt.title("Naive Forecast")
plt.show()
rms = sqrt(mean_squared_error(BTC_test.high, y_hat.naive))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
715.3385239816873
615.1448914605182
5765.8185907817815
5774.254910712047
1168.9608263521413 average rmse score is: 2807.903548657635
Avg_rms=[]
for train_index, test_index in btscv.split(BTC):
BTC_train, BTC_test = BTC.loc[train_index], BTC.loc[test_index]
y_hat_avg = BTC_test.copy()
y_hat_avg['avg_forecast'] = BTC_train['high'].mean()
plt.figure(figsize=(16,8))
plt.plot(BTC_train['high'], label='Train')
plt.plot(BTC_test['high'], label='Test')
plt.plot(y_hat_avg['avg_forecast'], label='Average Forecast')
plt.legend(loc='best')
plt.show()
rms = sqrt(mean_squared_error(BTC_test.high, y_hat_avg.avg_forecast))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
12577.66945578593
12154.28075269586
17931.10715378143
16562.027464154715
2984.0542320671416 average rmse score is: 12441.827811697016
Avg_rms=[]
for train_index, test_index in btscv.split(BTC):
BTC_train, BTC_test = BTC.loc[train_index], BTC.loc[test_index]
y_hat_avg = BTC_test.copy()
y_hat_avg['moving_avg_forecast'] = BTC_train['high'].rolling(14).mean().iloc[-1]
plt.figure(figsize=(16,8))
plt.plot(BTC_train['high'], label='Train')
plt.plot(BTC_test['high'], label='Test')
plt.plot(y_hat_avg['moving_avg_forecast'], label='Moving Average Forecast')
plt.legend(loc='best')
plt.show()
rms = sqrt(mean_squared_error(BTC_test.high, y_hat_avg.moving_avg_forecast))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
1743.8516583395665
1278.9112396194462
9994.629816393905
5498.211945892067
1637.3164682151178 average rmse score is: 4030.584225692021
Avg_rms=[]
for train_index, test_index in btscv.split(BTC):
BTC_train, BTC_test = BTC.loc[train_index], BTC.loc[test_index]
y_hat_avg = BTC_test.copy()
fit2 = SimpleExpSmoothing(np.asarray(BTC_train['high'])).fit(smoothing_level=0.6,optimized=False)
y_hat_avg['SES'] = fit2.forecast(len(BTC_test))
plt.figure(figsize=(16,8))
plt.plot(BTC_train['high'], label='Train')
plt.plot(BTC_test['high'], label='Test')
plt.plot(y_hat_avg['SES'], label='SES')
plt.legend(loc='best')
plt.show()
rms = sqrt(mean_squared_error(BTC_test.high, y_hat_avg.SES))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
701.0277077194593
801.6957298936993
6106.132456086461
5471.009798016659
1029.503144994298 average rmse score is: 2821.8737673421156
Avg_rms=[]
for train_index, test_index in btscv.split(BTC):
BTC_train, BTC_test = BTC.loc[train_index], BTC.loc[test_index]
y_hat_avg = BTC_test.copy()
fit1 = Holt(np.asarray(BTC_train['high'])).fit(smoothing_level = 0.3,smoothing_slope = 0.1)
y_hat_avg['Holt_linear'] = fit1.forecast(len(BTC_test))
plt.figure(figsize=(16,8))
plt.plot(BTC_train['high'], label='Train')
plt.plot(BTC_test['high'], label='Test')
plt.plot(y_hat_avg['Holt_linear'], label='Holt_linear')
plt.legend(loc='best')
plt.show()
rms = sqrt(mean_squared_error(BTC_test.high, y_hat_avg.Holt_linear))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
935.5301474193187
596.716981912761
2412.0973982297724
4206.717412497084
714.4101341164327 average rmse score is: 1773.094414835074
Avg_rms=[]
for train_index, test_index in btscv.split(BTC):
BTC_train, BTC_test = BTC.loc[train_index], BTC.loc[test_index]
y_hat_avg = BTC_test.copy()
fit1 = ExponentialSmoothing(np.asarray(BTC_train['high']) ,seasonal_periods=7 ,trend='add', seasonal='add',).fit()
y_hat_avg['Holt_Winter'] = fit1.forecast(len(BTC_test))
plt.figure(figsize=(16,8))
plt.plot(BTC_train['high'], label='Train')
plt.plot(BTC_test['high'], label='Test')
plt.plot(y_hat_avg['Holt_Winter'], label='Holt_Winter')
plt.legend(loc='best')
plt.show()
rms = sqrt(mean_squared_error(BTC_test.high, y_hat_avg.Holt_Winter))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
4298.018883000304
2159.9166291843308
3558.342255605656
5156.184828866718
652.9900424596615 average rmse score is: 3165.090527823334
Avg_rms=[]
for train_index, test_index in btscv.split(BTC):
BTC_train, BTC_test = BTC.loc[train_index], BTC.loc[test_index]
BTC_train.index=BTC_train.Date
BTC_test.index=BTC_test.Date
y_hat_avg = BTC_test.copy()
fit1 = sm.tsa.statespace.SARIMAX(BTC_train.high,seasonal_order=(0,1,1,7)).fit()
y_hat_avg['SARIMA'] = fit1.predict(start=BTC_test.Date[0], end=BTC_test.Date[-1], dynamic=True)
plt.figure(figsize=(16,8))
plt.plot(BTC_train['high'], label='Train')
plt.plot(BTC_test['high'], label='Test')
plt.plot(y_hat_avg['SARIMA'], label='SARIMA')
plt.legend(loc='best')
plt.show()
rms = sqrt(mean_squared_error(BTC_test.high, y_hat_avg.SARIMA))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
574.6157963631025
5051.694465151504
7125.957394655512
5548.193319715144
1061.366109957579 average rmse score is: 3872.365417168569
class BlockingTimeSeriesWeekSplit():
def __init__(self, n_splits):
self.n_splits = n_splits
def get_n_splits(self, X, y, groups):
return self.n_splits
def split(self, X, y=None, groups=None):
n_samples = len(X)
k_fold_size = n_samples // self.n_splits
indices = np.arange(n_samples)
margin = 0
for i in range(self.n_splits):
start = i * k_fold_size
stop = start + k_fold_size
last7 = int(0.95 * (stop - start)) + start
yield indices[start: last7], indices[last7 + margin: stop]
btswcv = BlockingTimeSeriesWeekSplit(n_splits=10)
btswcv.split(df_all)
for train_index, test_index in btswcv.split(df_all):
print("TRAIN:", train_index, "TEST:", test_index)
TRAIN: [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45] TEST: [46 47 48] TRAIN: [49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94] TEST: [95 96 97] TRAIN: [ 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143] TEST: [144 145 146] TRAIN: [147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192] TEST: [193 194 195] TRAIN: [196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241] TEST: [242 243 244] TRAIN: [245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290] TEST: [291 292 293] TRAIN: [294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339] TEST: [340 341 342] TRAIN: [343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388] TEST: [389 390 391] TRAIN: [392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437] TEST: [438 439 440] TRAIN: [441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486] TEST: [487 488 489]
### Naive Approach
Avg_rms=[]
for train_index, test_index in btswcv.split(BTC):
BTC_train, BTC_test = BTC.loc[train_index], BTC.loc[test_index]
dd= np.asarray(BTC_train.high)
y_hat = BTC_test.copy()
y_hat['naive'] = dd[len(dd)-1]
rms = sqrt(mean_squared_error(BTC_test.high, y_hat.naive))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
3081.1640716163233 1143.9557067237 631.5593162661486 1413.7048087401001 928.5085384980812 3550.8105848866744 601.8203389319547 919.8564280864883 1336.465304183957 681.6123278249241 average rmse score is: 1428.945742575835
#Simple Average
Avg_rms=[]
for train_index, test_index in btswcv.split(BTC):
BTC_train, BTC_test = BTC.loc[train_index], BTC.loc[test_index]
y_hat_avg = BTC_test.copy()
y_hat_avg['avg_forecast'] = BTC_train['high'].mean()
rms = sqrt(mean_squared_error(BTC_test.high, y_hat_avg.avg_forecast))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
13285.758089961893 2957.145016772615 14530.807526514913 3325.3106476073117 6383.389796099388 15567.420194165934 9906.468750294707 8454.371333348803 852.5063903113423 3514.095366484132 average rmse score is: 7877.7273111561035
# Moving Average
Avg_rms=[]
for train_index, test_index in btswcv.split(BTC):
BTC_train, BTC_test = BTC.loc[train_index], BTC.loc[test_index]
y_hat_avg = BTC_test.copy()
y_hat_avg['moving_avg_forecast'] = BTC_train['high'].rolling(14).mean().iloc[-1]
rms = sqrt(mean_squared_error(BTC_test.high, y_hat_avg.moving_avg_forecast))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
7875.295654458483 1007.589698870894 6522.801983195482 1756.1400407108567 939.9444402283406 8110.8651963776065 5392.203535331906 4043.241459459013 837.4257869297031 1051.0696736890334 average rmse score is: 3753.6577469251315
#Simple Exponential Smoothing
Avg_rms=[]
for train_index, test_index in btswcv.split(BTC):
BTC_train, BTC_test = BTC.loc[train_index], BTC.loc[test_index]
y_hat_avg = BTC_test.copy()
fit2 = SimpleExpSmoothing(np.asarray(BTC_train['high'])).fit(smoothing_level=0.6,optimized=False)
y_hat_avg['SES'] = fit2.forecast(len(BTC_test))
rms = sqrt(mean_squared_error(BTC_test.high, y_hat_avg.SES))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
3048.4638923617317 957.9881957616648 868.4335163887488 1348.5629057022932 884.5894863761123 3908.7738706057303 478.17376509851823 892.0070696370924 1425.64968014824 726.967892738755 average rmse score is: 1453.9610274818888
# Holt’s Linear Trend method
Avg_rms=[]
for train_index, test_index in btswcv.split(BTC):
BTC_train, BTC_test = BTC.loc[train_index], BTC.loc[test_index]
y_hat_avg = BTC_test.copy()
fit1 = Holt(np.asarray(BTC_train['high'])).fit(smoothing_level = 0.3,smoothing_slope = 0.1)
y_hat_avg['Holt_linear'] = fit1.forecast(len(BTC_test))
rms = sqrt(mean_squared_error(BTC_test.high, y_hat_avg.Holt_linear))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
609.1964712569078 1437.0903586835252 3907.289879165501 961.0247820987092 1204.848257688247 1616.4179264445202 272.57544737247906 1114.5790669188696 1570.934370866056 1176.7349322655455 average rmse score is: 1387.0691492760361
#Holt-Winters Method
Avg_rms=[]
for train_index, test_index in btswcv.split(BTC):
BTC_train, BTC_test = BTC.loc[train_index], BTC.loc[test_index]
y_hat_avg = BTC_test.copy()
fit1 = ExponentialSmoothing(np.asarray(BTC_train['high']) ,seasonal_periods=7 ,trend='add', seasonal='add',).fit()
y_hat_avg['Holt_Winter'] = fit1.forecast(len(BTC_test))
rms = sqrt(mean_squared_error(BTC_test.high, y_hat_avg.Holt_Winter))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
2321.1638305323645 3259.315802908007 302.00981626617073 1867.8598424999764 1253.6170679716913 1898.3477444074524 2439.580463848579 2165.551361501345 1326.429169462573 1166.2145624535833 average rmse score is: 1800.008966185174
# ARIMA
Avg_rms=[]
for train_index, test_index in btswcv.split(BTC):
BTC_train, BTC_test = BTC.loc[train_index], BTC.loc[test_index]
BTC_train.index=BTC_train.Date
BTC_test.index=BTC_test.Date
y_hat_avg = BTC_test.copy()
fit1 = sm.tsa.statespace.SARIMAX(BTC_train.high,seasonal_order=(0,1,1,7)).fit()
y_hat_avg['SARIMA'] = fit1.predict(start=BTC_test.Date[0], end=BTC_test.Date[-1], dynamic=True)
rms = sqrt(mean_squared_error(BTC_test.high, y_hat_avg.SARIMA))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
4370.374872325807 627.0116554528295 3672.9780208889256 1569.3948385886508 2718.509255168343 7881.6411473446815 6830.673814260035 4814.90785721324 719.4898680353004 1162.2045976160591 average rmse score is: 3436.718592689387
BTC_data = df_all[['Date']+[coin+metric for coin in ['BTC_']
for metric in ['high','close_off_high','volatility','day_diff']]]
BTC_data.head(3)
| Date | BTC_high | BTC_close_off_high | BTC_volatility | BTC_day_diff | |
|---|---|---|---|---|---|
| 0 | 2021-01-01 | 29600.626953 | 0.284144 | 0.027490 | 0.013111 |
| 1 | 2021-01-02 | 33155.117188 | 0.252920 | 0.138340 | 0.093640 |
| 2 | 2021-01-03 | 34608.558594 | 0.714539 | 0.079561 | 0.020312 |
#transform the numerical data
BTC_data_num = BTC_data[['BTC_close_off_high','BTC_volatility','BTC_day_diff']].set_index(BTC_data.index)
scaler =StandardScaler().fit(BTC_data_num)
BTC_data_num_scaled = scaler.transform(BTC_data_num) # this will return an array
# Convert the array to a pandas dataframe
BTC_data_num_scaled = pd.DataFrame(BTC_data_num_scaled, columns = BTC_data_num.columns).set_index(BTC_data.index)
BTC_data= BTC_data_num_scaled.join(BTC_data[['Date','BTC_high']])
BTC_data.head(3)
| BTC_close_off_high | BTC_volatility | BTC_day_diff | Date | BTC_high | |
|---|---|---|---|---|---|
| 0 | -0.605117 | -0.857257 | 0.303318 | 2021-01-01 | 29600.626953 |
| 1 | -0.707106 | 2.217484 | 2.313654 | 2021-01-02 | 33155.117188 |
| 2 | 0.800691 | 0.587079 | 0.483085 | 2021-01-03 | 34608.558594 |
fig = px.line(BTC_data, x="Date", y=['BTC_close_off_high','BTC_volatility','BTC_day_diff'],
hover_data={"Date"},
title='Daliy High price of Ten Cryptocurrenies')
fig.update_xaxes(rangeslider_visible=True)
fig.update_yaxes(type="log")
fig.show()
class FBlockingTimeSeriesSplit():
def __init__(self, n_splits):
self.n_splits = n_splits
def get_n_splits(self, X, y, groups):
return self.n_splits
def split(self, X, y=None, groups=None):
n_samples = len(X)
k_fold_size = n_samples // self.n_splits
indices = np.arange(n_samples)
margin = 0
for i in range(self.n_splits):
start = i * k_fold_size
stop = start + k_fold_size
last7 = int(0.95 * (stop - start)) + start
yield indices[start: last7], indices[last7 + margin: stop]
fbtscv = FBlockingTimeSeriesSplit(n_splits=5)
fbtscv.split(BTC_data)
for train_index, test_index in fbtscv.split(BTC_data):
print("TRAIN:", train_index, "TEST:", test_index)
TRAIN: [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92] TEST: [93 94 95 96 97] TRAIN: [ 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190] TEST: [191 192 193 194 195] TRAIN: [196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288] TEST: [289 290 291 292 293] TRAIN: [294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386] TEST: [387 388 389 390 391] TRAIN: [392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484] TEST: [485 486 487 488 489]
Avg_rms=[]
for train_index, test_index in fbtscv.split(BTC_data):
BTC_train, BTC_test = BTC_data.loc[train_index], BTC_data.loc[test_index]
y_hat_avg = BTC_test.copy()
y_hat_avg['moving_avg_forecast'] = BTC_train['BTC_close_off_high'].rolling(14).mean().iloc[-1]
rms = sqrt(mean_squared_error(BTC_test.BTC_close_off_high, y_hat_avg.moving_avg_forecast))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
1.1383354060699262 0.7741591856867903 1.1691337660757632 1.1930650846785456 1.0653606497156494 average rmse score is: 1.068010818445335
#Simple Exponential Smoothing
Avg_rms=[]
for train_index, test_index in fbtscv.split(BTC_data):
BTC_train, BTC_test = BTC_data.loc[train_index], BTC_data.loc[test_index]
y_hat_avg = BTC_test.copy()
fit2 = SimpleExpSmoothing(np.asarray(BTC_train['BTC_close_off_high'])).fit(smoothing_level=0.6,optimized=False)
y_hat_avg['SES'] = fit2.forecast(len(BTC_test))
rms = sqrt(mean_squared_error(BTC_test.BTC_close_off_high, y_hat_avg.SES))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
1.7299813405701232 0.7646392514400191 1.3310210794503463 1.8546102818749641 1.5089547719882461 average rmse score is: 1.4378413450647398
# ARIMA
Avg_rms=[]
for train_index, test_index in fbtscv.split(BTC_data):
BTC_train, BTC_test = BTC_data.loc[train_index], BTC_data.loc[test_index]
BTC_train.index=BTC_train.Date
BTC_test.index=BTC_test.Date
y_hat_avg = BTC_test.copy()
fit1 = sm.tsa.statespace.SARIMAX(BTC_train.BTC_close_off_high,seasonal_order=(0,1,1,7)).fit()
y_hat_avg['SARIMA'] = fit1.predict(start=BTC_test.Date[0], end=BTC_test.Date[-1], dynamic=True)
rms = sqrt(mean_squared_error(BTC_test.BTC_close_off_high, y_hat_avg.SARIMA))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
1.2545731439554362 0.7716714439804867 1.3266551578078696 1.2974685169835158 1.1881185901181568 average rmse score is: 1.167697370569093
Avg_rms=[]
for train_index, test_index in fbtscv.split(BTC_data):
BTC_train, BTC_test = BTC_data.loc[train_index], BTC_data.loc[test_index]
y_hat_avg = BTC_test.copy()
y_hat_avg['moving_avg_forecast'] = BTC_train['BTC_volatility'].rolling(14).mean().iloc[-1]
rms = sqrt(mean_squared_error(BTC_test.BTC_volatility, y_hat_avg.moving_avg_forecast))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
0.3224022683326507 0.3187595041053567 0.2822615846880891 0.8734976129150513 0.8342166976823013 average rmse score is: 0.5262275335446899
#Simple Exponential Smoothing
Avg_rms=[]
for train_index, test_index in fbtscv.split(BTC_data):
BTC_train, BTC_test = BTC_data.loc[train_index], BTC_data.loc[test_index]
y_hat_avg = BTC_test.copy()
fit2 = SimpleExpSmoothing(np.asarray(BTC_train['BTC_volatility'])).fit(smoothing_level=0.6,optimized=False)
y_hat_avg['SES'] = fit2.forecast(len(BTC_test))
rms = sqrt(mean_squared_error(BTC_test.BTC_volatility, y_hat_avg.SES))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
0.26665825564534806 0.3428394644089882 0.2773792766896665 0.8430717160518937 0.8894927210202151 average rmse score is: 0.5238882867632223
# ARIMA
Avg_rms=[]
for train_index, test_index in fbtscv.split(BTC_data):
BTC_train, BTC_test = BTC_data.loc[train_index], BTC_data.loc[test_index]
BTC_train.index=BTC_train.Date
BTC_test.index=BTC_test.Date
y_hat_avg = BTC_test.copy()
fit1 = sm.tsa.statespace.SARIMAX(BTC_train.BTC_volatility,seasonal_order=(0,1,1,7)).fit()
y_hat_avg['SARIMA'] = fit1.predict(start=BTC_test.Date[0], end=BTC_test.Date[-1], dynamic=True)
rms = sqrt(mean_squared_error(BTC_test.BTC_volatility, y_hat_avg.SARIMA))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
0.8797750100015609 0.8351616433746265 0.43606969056619155 0.8138158381373608 0.7718287518041397 average rmse score is: 0.7473301867767759
Avg_rms=[]
for train_index, test_index in fbtscv.split(BTC_data):
BTC_train, BTC_test = BTC_data.loc[train_index], BTC_data.loc[test_index]
y_hat_avg = BTC_test.copy()
y_hat_avg['moving_avg_forecast'] = BTC_train['BTC_day_diff'].rolling(14).mean().iloc[-1]
rms = sqrt(mean_squared_error(BTC_test.BTC_day_diff, y_hat_avg.moving_avg_forecast))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
0.6726728691744928 0.6182193930873813 0.883136721543319 0.6707386429742798 1.08994339503896 average rmse score is: 0.7869422043636864
#Simple Exponential Smoothing
Avg_rms=[]
for train_index, test_index in fbtscv.split(BTC_data):
BTC_train, BTC_test = BTC_data.loc[train_index], BTC_data.loc[test_index]
y_hat_avg = BTC_test.copy()
fit2 = SimpleExpSmoothing(np.asarray(BTC_train['BTC_day_diff'])).fit(smoothing_level=0.6,optimized=False)
y_hat_avg['SES'] = fit2.forecast(len(BTC_test))
rms = sqrt(mean_squared_error(BTC_test.BTC_day_diff, y_hat_avg.SES))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
0.8123808223970508 0.5629756754921302 0.8346655134488845 1.6188920075924345 1.1448182264295337 average rmse score is: 0.9947464490720067
# ARIMA
Avg_rms=[]
for train_index, test_index in fbtscv.split(BTC_data):
BTC_train, BTC_test = BTC_data.loc[train_index], BTC_data.loc[test_index]
BTC_train.index=BTC_train.Date
BTC_test.index=BTC_test.Date
y_hat_avg = BTC_test.copy()
fit1 = sm.tsa.statespace.SARIMAX(BTC_train.BTC_day_diff,seasonal_order=(0,1,1,7)).fit()
y_hat_avg['SARIMA'] = fit1.predict(start=BTC_test.Date[0], end=BTC_test.Date[-1], dynamic=True)
rms = sqrt(mean_squared_error(BTC_test.BTC_day_diff, y_hat_avg.SARIMA))
Avg_rms.append(rms)
print(rms)
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
0.8355099789243976 0.5518406310126703 0.9265775021899432 0.4851416490346077 1.0071786196036558 average rmse score is: 0.761249676153055
model = linear_model.BayesianRidge()
Avg_rms=[]
for train_index, test_index in fbtscv.split(BTC_data):
BTC_train, BTC_test = BTC_data.loc[train_index], BTC_data.loc[test_index]
BTC_train.index=BTC_train.Date
BTC_test.index=BTC_test.Date
#predict BTC_close_off_high
fit1 = sm.tsa.statespace.SARIMAX(BTC_train.BTC_close_off_high,seasonal_order=(0,1,1,7)).fit()
BTC_test['BTC_close_off_high_P'] = fit1.predict(start=BTC_test.Date.iloc[0], end=BTC_test.Date.iloc[-1], dynamic=True)
#predict BTC_volatility
fit2 = sm.tsa.statespace.SARIMAX(BTC_train.BTC_volatility,seasonal_order=(0,1,1,7)).fit()
BTC_test['BTC_volatility_P'] = fit2.predict(start=BTC_test.Date.iloc[0], end=BTC_test.Date.iloc[-1], dynamic=True)
#predict BTC_day_diff
fit3 = sm.tsa.statespace.SARIMAX(BTC_train.BTC_day_diff,seasonal_order=(0,1,1,7)).fit()
BTC_test['BTC_day_diff_P'] = fit3.predict(start=BTC_test.Date.iloc[0], end=BTC_test.Date.iloc[-1], dynamic=True)
#predict BTC_high
fit4 = Holt(np.asarray(BTC_train['BTC_high'])).fit(smoothing_level = 0.3,smoothing_slope = 0.1)
BTC_test['BTC_high_P'] = fit4.forecast(len(BTC_test))
#use suspective model to predict the target BTC_high
model = model.fit(BTC_train[['BTC_close_off_high','BTC_volatility','BTC_day_diff','BTC_high']], BTC_train.BTC_high)
y_pred= model.predict(BTC_test[['BTC_close_off_high_P','BTC_volatility_P','BTC_day_diff_P','BTC_high_P']])
rms = sqrt(mean_squared_error(BTC_test.BTC_high, y_pred))
Avg_rms.append(rms)
print(rms)
plt.figure(figsize=(16,8))
plt.plot(BTC_test['BTC_high'], label='actual')
plt.plot(BTC_test['BTC_high_P'], label='BTC_high_P')
plt.plot(BTC_test.Date,y_pred, label='pred')
plt.legend(loc='best')
plt.show()
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
1438.3666474471624
589.0107413942942
1047.6672397713744
2045.0417870883728
875.9424756902924
average rmse score is: 1199.2057782782992
from sklearn.linear_model import LinearRegression
model = LinearRegression()
Avg_rms=[]
for train_index, test_index in fbtscv.split(BTC_data):
BTC_train, BTC_test = BTC_data.loc[train_index], BTC_data.loc[test_index]
BTC_train.index=BTC_train.Date
BTC_test.index=BTC_test.Date
#predict BTC_close_off_high
fit1 = sm.tsa.statespace.SARIMAX(BTC_train.BTC_close_off_high,seasonal_order=(0,1,1,7)).fit()
BTC_test['BTC_close_off_high_P'] = fit1.predict(start=BTC_test.Date.iloc[0], end=BTC_test.Date.iloc[-1], dynamic=True)
#predict BTC_volatility
fit2 = sm.tsa.statespace.SARIMAX(BTC_train.BTC_volatility,seasonal_order=(0,1,1,7)).fit()
BTC_test['BTC_volatility_P'] = fit2.predict(start=BTC_test.Date.iloc[0], end=BTC_test.Date.iloc[-1], dynamic=True)
#predict BTC_day_diff
fit3 = sm.tsa.statespace.SARIMAX(BTC_train.BTC_day_diff,seasonal_order=(0,1,1,7)).fit()
BTC_test['BTC_day_diff_P'] = fit3.predict(start=BTC_test.Date.iloc[0], end=BTC_test.Date.iloc[-1], dynamic=True)
#predict BTC_high
fit4 = Holt(np.asarray(BTC_train['BTC_high'])).fit(smoothing_level = 0.3,smoothing_slope = 0.1)
BTC_test['BTC_high_P'] = fit4.forecast(len(BTC_test))
#use suspective model to predict the target BTC_high
model = model.fit(BTC_train[['BTC_close_off_high','BTC_volatility','BTC_day_diff','BTC_high']], BTC_train.BTC_high)
y_pred= model.predict(BTC_test[['BTC_close_off_high_P','BTC_volatility_P','BTC_day_diff_P','BTC_high_P']])
rms = sqrt(mean_squared_error(BTC_test.BTC_high, y_pred))
Avg_rms.append(rms)
print(rms)
plt.figure(figsize=(16,8))
plt.plot(BTC_test['BTC_high'], label='actual')
plt.plot(BTC_test['BTC_high_P'], label='BTC_high_P')
plt.plot(BTC_test.Date,y_pred, label='pred')
plt.legend(loc='best')
plt.show()
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
1438.3666474467354
589.0107413942694
1047.667239771437
2045.0417870885387
875.9424756903163
average rmse score is: 1199.2057782782592
model = RandomForestRegressor()
Avg_rms=[]
for train_index, test_index in fbtscv.split(BTC_data):
BTC_train, BTC_test = BTC_data.loc[train_index], BTC_data.loc[test_index]
BTC_train.index=BTC_train.Date
BTC_test.index=BTC_test.Date
#predict BTC_close_off_high
fit1 = sm.tsa.statespace.SARIMAX(BTC_train.BTC_close_off_high,seasonal_order=(0,1,1,7)).fit()
BTC_test['BTC_close_off_high_P'] = fit1.predict(start=BTC_test.Date.iloc[0], end=BTC_test.Date.iloc[-1], dynamic=True)
#predict BTC_volatility
fit2 = sm.tsa.statespace.SARIMAX(BTC_train.BTC_volatility,seasonal_order=(0,1,1,7)).fit()
BTC_test['BTC_volatility_P'] = fit2.predict(start=BTC_test.Date.iloc[0], end=BTC_test.Date.iloc[-1], dynamic=True)
#predict BTC_day_diff
fit3 = sm.tsa.statespace.SARIMAX(BTC_train.BTC_day_diff,seasonal_order=(0,1,1,7)).fit()
BTC_test['BTC_day_diff_P'] = fit3.predict(start=BTC_test.Date.iloc[0], end=BTC_test.Date.iloc[-1], dynamic=True)
#predict BTC_high
fit4 = Holt(np.asarray(BTC_train['BTC_high'])).fit(smoothing_level = 0.3,smoothing_slope = 0.1)
BTC_test['BTC_high_P'] = fit4.forecast(len(BTC_test))
#use suspective model to predict the target BTC_high
model = model.fit(BTC_train[['BTC_close_off_high','BTC_volatility','BTC_day_diff','BTC_high']], BTC_train.BTC_high)
y_pred= model.predict(BTC_test[['BTC_close_off_high_P','BTC_volatility_P','BTC_day_diff_P','BTC_high_P']])
rms = sqrt(mean_squared_error(BTC_test.BTC_high, y_pred))
Avg_rms.append(rms)
print(rms)
plt.figure(figsize=(16,8))
plt.plot(BTC_test['BTC_high'], label='actual')
plt.plot(BTC_test['BTC_high_P'], label='BTC_high_P')
plt.plot(BTC_test.Date,y_pred, label='pred')
plt.legend(loc='best')
plt.show()
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
1140.97003013174
698.0092493069874
3862.796944475507
4039.630658133911
857.8516688471759
average rmse score is: 2119.8517101790644
model = MLPRegressor()
Avg_rms=[]
for train_index, test_index in fbtscv.split(BTC_data):
BTC_train, BTC_test = BTC_data.loc[train_index], BTC_data.loc[test_index]
BTC_train.index=BTC_train.Date
BTC_test.index=BTC_test.Date
#predict BTC_close_off_high
fit1 = sm.tsa.statespace.SARIMAX(BTC_train.BTC_close_off_high,seasonal_order=(0,1,1,7)).fit()
BTC_test['BTC_close_off_high_P'] = fit1.predict(start=BTC_test.Date.iloc[0], end=BTC_test.Date.iloc[-1], dynamic=True)
#predict BTC_volatility
fit2 = sm.tsa.statespace.SARIMAX(BTC_train.BTC_volatility,seasonal_order=(0,1,1,7)).fit()
BTC_test['BTC_volatility_P'] = fit2.predict(start=BTC_test.Date.iloc[0], end=BTC_test.Date.iloc[-1], dynamic=True)
#predict BTC_day_diff
fit3 = sm.tsa.statespace.SARIMAX(BTC_train.BTC_day_diff,seasonal_order=(0,1,1,7)).fit()
BTC_test['BTC_day_diff_P'] = fit3.predict(start=BTC_test.Date.iloc[0], end=BTC_test.Date.iloc[-1], dynamic=True)
#predict BTC_high
fit4 = Holt(np.asarray(BTC_train['BTC_high'])).fit(smoothing_level = 0.3,smoothing_slope = 0.1)
BTC_test['BTC_high_P'] = fit4.forecast(len(BTC_test))
#use suspective model to predict the target BTC_high
model = model.fit(BTC_train[['BTC_close_off_high','BTC_volatility','BTC_day_diff','BTC_high']], BTC_train.BTC_high)
y_pred= model.predict(BTC_test[['BTC_close_off_high_P','BTC_volatility_P','BTC_day_diff_P','BTC_high_P']])
rms = sqrt(mean_squared_error(BTC_test.BTC_high, y_pred))
Avg_rms.append(rms)
print(rms)
plt.figure(figsize=(16,8))
plt.plot(BTC_test['BTC_high'], label='actual')
plt.plot(BTC_test['BTC_high_P'], label='BTC_high_P')
plt.plot(BTC_test.Date,y_pred, label='pred')
plt.legend(loc='best')
plt.show()
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
1530.3282503879564
622.8843728933831
1005.9441699728936
2174.6077861493463
778.3767403736753
average rmse score is: 1222.428263955451
def cryptocurrency_predictor(data,close_off_high,volatility,day_diff,high,start,end):
#predict BTC_close_off_high
fit1 = sm.tsa.statespace.SARIMAX(close_off_high,seasonal_order=(0,1,1,7)).fit()
y_pred['close_off_high_P'] = fit1.predict(start=start, end=end, dynamic=True)
#predict BTC_volatility
fit2 = sm.tsa.statespace.SARIMAX(data.volatility,seasonal_order=(0,1,1,7)).fit()
y_pred['volatility_P'] = fit2.predict(start=start, end=end, dynamic=True)
#predict BTC_day_diff
fit3 = sm.tsa.statespace.SARIMAX(data.day_diff,seasonal_order=(0,1,1,7)).fit()
y_pred['day_diff_P'] = fit3.predict(start=start, end=end, dynamic=True)
#predict BTC_high
fit4 = Holt(np.asarray(data.high)).fit(smoothing_level = 0.3,smoothing_slope = 0.1)
y_pred['high_P'] = fit4.forecast(len(end-start))
#use suspective model to predict the target BTC_high
model = MLPRegressor().fit(data[['close_off_high','volatility','day_diff','high']], data.high)
y_pred['high_FP']= model.predict(y_pred[['close_off_high_P','volatility_P','day_diff_P','high_P']])
return y_pred
ETH_data = df_all[['Date']+[coin+metric for coin in ['ETH_']
for metric in ['high','close_off_high','volatility','day_diff']]]
#transform the numerical data
ETH_data_num = ETH_data[['ETH_close_off_high','ETH_volatility','ETH_day_diff']].set_index(ETH_data.index)
scaler =StandardScaler().fit(ETH_data_num)
ETH_data_num_scaled = scaler.transform(ETH_data_num) # this will return an array
# Convert the array to a pandas dataframe
ETH_data_num_scaled = pd.DataFrame(ETH_data_num_scaled, columns = ETH_data_num.columns).set_index(ETH_data.index)
ETH_data= ETH_data_num_scaled.join(ETH_data[['Date','ETH_high']])
ETH_data.columns=['close_off_high','volatility','day_diff', 'Date','high']
ETH_data.head(3)
| close_off_high | volatility | day_diff | Date | high | |
|---|---|---|---|---|---|
| 0 | 0.628354 | -0.730439 | -0.261429 | 2021-01-01 | 749.201843 |
| 1 | -0.841496 | 0.413837 | 1.085428 | 2021-01-02 | 786.798462 |
| 2 | -0.989092 | 4.836186 | 4.895810 | 2021-01-03 | 1006.565002 |
model = MLPRegressor()
Avg_rms=[]
for train_index, test_index in fbtscv.split(ETH_data):
train, test = ETH_data.loc[train_index], ETH_data.loc[test_index]
train.index=train.Date
test.index=test.Date
#predict BTC_close_off_high
fit1 = sm.tsa.statespace.SARIMAX(train.close_off_high,seasonal_order=(0,1,1,7)).fit()
test['close_off_high_P'] = fit1.predict(start=test.Date.iloc[0], end=test.Date.iloc[-1], dynamic=True)
#predict BTC_volatility
fit2 = sm.tsa.statespace.SARIMAX(train.volatility,seasonal_order=(0,1,1,7)).fit()
test['volatility_P'] = fit2.predict(start=test.Date.iloc[0], end=test.Date.iloc[-1], dynamic=True)
#predict BTC_day_diff
fit3 = sm.tsa.statespace.SARIMAX(train.day_diff,seasonal_order=(0,1,1,7)).fit()
test['day_diff_P'] = fit3.predict(start=test.Date.iloc[0], end=test.Date.iloc[-1], dynamic=True)
#predict BTC_high
fit4 = Holt(np.asarray(train['high'])).fit(smoothing_level = 0.3,smoothing_slope = 0.1)
test['high_P'] = fit4.forecast(len(test))
#use suspective model to predict the target BTC_high
model = model.fit(train[['close_off_high','volatility','day_diff','high']], train.high)
y_pred= model.predict(test[['close_off_high_P','volatility_P','day_diff_P','high_P']])
rms = sqrt(mean_squared_error(test.high, y_pred))
Avg_rms.append(rms)
print(rms)
plt.figure(figsize=(16,8))
plt.plot(test['high'], label='actual')
plt.plot(test['high_P'], label='high_P')
plt.plot(test.Date,y_pred, label='pred')
plt.legend(loc='best')
plt.show()
print('average rmse score is: ',sum(Avg_rms) / len(Avg_rms))
44.46490069967301
208.08719511774393
165.832500810623
302.6961016114259
80.94502343157063
average rmse score is: 160.4051443342073
split_date = '2022-05-01'
fig, (ax1, ax2) = plt.subplots(2,1,figsize=(15,15))
ax1.plot(BTC[BTC['Date'] < split_date]['Date'],
BTC[BTC['Date'] < split_date]['high'],
color='#B08FC7', label='Training')
ax1.plot(BTC[BTC['Date'] >= split_date]['Date'],
BTC[BTC['Date'] >= split_date]['high'],
color='#8FBAC8', label='Evaluation')
ax2.plot(ETH[ETH['Date'] < split_date]['Date'],
ETH[ETH['Date'] < split_date]['high'],
color='#B08FC7')
ax2.plot(ETH[ETH['Date'] >= split_date]['Date'],
ETH[ETH['Date'] >= split_date]['high'], color='#8FBAC8')
ax1.set_xticklabels('')
ax1.set_ylabel('Bitcoin Price ($)',fontsize=12)
ax2.set_ylabel('Ethereum Price ($)',fontsize=12)
plt.tight_layout()
ax1.legend(bbox_to_anchor=(0.03, 1), loc=2, borderaxespad=0., prop={'size': 14})
plt.show()
BTC_train = BTC_data[BTC_data['Date'] < split_date]
BTC_evaluation = BTC_data[BTC_data['Date'] >= split_date]
BTC_train.index=BTC_train.Date
BTC_evaluation.index=BTC_evaluation.Date
fit1 = SimpleExpSmoothing(np.asarray(BTC_train['BTC_high'])).fit(smoothing_level=0.6,optimized=False)
BTC_evaluation['SES'] = fit1.forecast(len(BTC_evaluation))
fit2 = ExponentialSmoothing(np.asarray(BTC_train['BTC_high']) ,seasonal_periods=7 ,trend='add', seasonal='add',).fit()
BTC_evaluation['Holt_Winter'] = fit2.forecast(len(BTC_evaluation))
fit3 = sm.tsa.statespace.SARIMAX(BTC_train.BTC_high,seasonal_order=(0,1,1,7)).fit()
BTC_evaluation['SARIMA'] = fit3.predict(start=BTC_evaluation.Date.iloc[0], end=BTC_evaluation.Date.iloc[-1], dynamic=True)
model = MLPRegressor()
#predict BTC_close_off_high
fit1 = sm.tsa.statespace.SARIMAX(BTC_train.BTC_close_off_high,seasonal_order=(0,1,1,7)).fit()
BTC_evaluation['BTC_close_off_high_P'] = fit1.predict(start=BTC_evaluation.Date.iloc[0], end=BTC_evaluation.Date.iloc[-1], dynamic=True)
#predict BTC_volatility
fit2 = sm.tsa.statespace.SARIMAX(BTC_train.BTC_volatility,seasonal_order=(0,1,1,7)).fit()
BTC_evaluation['BTC_volatility_P'] = fit2.predict(start=BTC_evaluation.Date.iloc[0], end=BTC_evaluation.Date.iloc[-1], dynamic=True)
#predict BTC_day_diff
fit3 = sm.tsa.statespace.SARIMAX(BTC_train.BTC_day_diff,seasonal_order=(0,1,1,7)).fit()
BTC_evaluation['BTC_day_diff_P'] = fit3.predict(start=BTC_evaluation.Date.iloc[0], end=BTC_evaluation.Date.iloc[-1], dynamic=True)
#predict BTC_high
fit4 = Holt(np.asarray(BTC_train['BTC_high'])).fit(smoothing_level = 0.3,smoothing_slope = 0.1)
BTC_evaluation['BTC_high_P'] = fit4.forecast(len(BTC_evaluation))
#use suspective model to predict the target BTC_high
model = model.fit(BTC_train[['BTC_close_off_high','BTC_volatility','BTC_day_diff','BTC_high']], BTC_train.BTC_high)
BTC_evaluation['MLP']= model.predict(BTC_evaluation[['BTC_close_off_high_P','BTC_volatility_P','BTC_day_diff_P','BTC_high_P']])
BTC_evaluation
| BTC_close_off_high | BTC_volatility | BTC_day_diff | Date | BTC_high | SES | Holt_Winter | SARIMA | BTC_close_off_high_P | BTC_volatility_P | BTC_day_diff_P | BTC_high_P | MLP | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Date | |||||||||||||
| 2022-05-01 | -1.035580 | -0.853331 | 0.476328 | 2022-05-01 | 38627.859375 | 39252.916009 | 38958.412013 | 38764.849184 | 0.141897 | -0.641808 | 0.039847 | 39162.059138 | 39194.611410 |
| 2022-05-02 | 0.407359 | -0.957607 | 0.013089 | 2022-05-02 | 39074.972656 | 39252.916009 | 39002.639421 | 39172.511557 | -0.162076 | -0.047963 | 0.034566 | 38978.897748 | 39011.011534 |
| 2022-05-03 | 1.217580 | -0.867882 | -0.527868 | 2022-05-03 | 38629.996094 | 39252.916009 | 39009.925992 | 38899.693446 | 0.003161 | -0.419757 | -0.019343 | 38795.736358 | 38827.869886 |
| 2022-05-04 | -1.225415 | -0.024561 | 1.265855 | 2022-05-04 | 39902.949219 | 39252.916009 | 39066.389080 | 39079.064556 | 0.008885 | -0.378994 | 0.129162 | 38612.574967 | 38644.562014 |
| 2022-05-05 | 1.136251 | 1.128298 | -1.986498 | 2022-05-05 | 39789.281250 | 39252.916009 | 39641.682333 | 38944.151265 | 0.360045 | -0.280930 | -0.124200 | 38429.413577 | 38461.273320 |
| 2022-05-06 | 0.135180 | -0.753479 | -0.387301 | 2022-05-06 | 36624.359375 | 39252.916009 | 38756.427483 | 39189.430416 | 0.169332 | -0.270034 | 0.003009 | 38246.252187 | 38277.926522 |
| 2022-05-07 | 0.191744 | -0.704649 | -0.398391 | 2022-05-07 | 36129.925781 | 39252.916009 | 38232.348859 | 38698.882553 | 0.020253 | -0.899644 | -0.004344 | 38063.090796 | 38094.807472 |
| 2022-05-08 | 1.079553 | -0.397187 | -0.901175 | 2022-05-08 | 35477.484375 | 39252.916009 | 38287.775309 | 38693.127403 | 0.145003 | -0.658359 | 0.015800 | 37879.929406 | 37911.441751 |
plt.figure(figsize=(16,8))
plt.plot(BTC_evaluation['BTC_high'], label='actual')
plt.plot(BTC_evaluation['SES'], label='SES')
plt.plot(BTC_evaluation['Holt_Winter'], label='Holt_Winter')
plt.plot(BTC_evaluation['SARIMA'], label='SARIMA')
plt.plot(BTC_evaluation['MLP'], label='MLP')
plt.legend(loc='best')
plt.ylabel('Bitcoin Price ($)',fontsize=12)
plt.tight_layout()
plt.legend(bbox_to_anchor=(0.03, 1), loc=2, borderaxespad=0., prop={'size': 14})
plt.show()
print('SES RMS SCORE: ',sqrt(mean_squared_error(BTC_evaluation.BTC_high, BTC_evaluation.SES)))
print('Holt_Winter RMS SCORE: ',sqrt(mean_squared_error(BTC_evaluation.BTC_high, BTC_evaluation.Holt_Winter)))
print('SARIMA RMS SCORE: ',sqrt(mean_squared_error(BTC_evaluation.BTC_high, BTC_evaluation.SARIMA)))
print('MLP RMS SCORE: ',sqrt(mean_squared_error(BTC_evaluation.BTC_high, BTC_evaluation.MLP)))
SES RMS SCORE: 2013.6062694968205 Holt_Winter RMS SCORE: 1493.4898109644903 SARIMA RMS SCORE: 1768.245449435916 MLP RMS SCORE: 1424.376584160585
Goal = pd.DataFrame({'Date':['2022-05-09','2022-05-10','2022-05-11','2022-05-12','2022-05-13','2022-05-14','2022-05-15']})
Goal['Date']= pd.to_datetime(Goal['Date'])
Goal
| Date | |
|---|---|
| 0 | 2022-05-09 |
| 1 | 2022-05-10 |
| 2 | 2022-05-11 |
| 3 | 2022-05-12 |
| 4 | 2022-05-13 |
| 5 | 2022-05-14 |
| 6 | 2022-05-15 |
model = MLPRegressor()
df_all.index=df_all.Date
Goal.index=Goal.Date
#predict BTC_close_off_high
fit1 = sm.tsa.statespace.SARIMAX(df_all.BTC_close_off_high,seasonal_order=(0,1,1,7)).fit()
Goal['BTC_close_off_high_P'] = fit1.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_volatility
fit2 = sm.tsa.statespace.SARIMAX(df_all.BTC_volatility,seasonal_order=(0,1,1,7)).fit()
Goal['BTC_volatility_P'] = fit2.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_day_diff
fit3 = sm.tsa.statespace.SARIMAX(df_all.BTC_day_diff,seasonal_order=(0,1,1,7)).fit()
Goal['BTC_day_diff_P'] = fit3.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_high
fit4 = Holt(np.asarray(df_all['BTC_high'])).fit(smoothing_level = 0.3,smoothing_slope = 0.1)
Goal['BTC_high_P'] = fit4.forecast(len(Goal))
#use suspective model to predict the target BTC_high
model = model.fit(df_all[['BTC_close_off_high','BTC_volatility','BTC_day_diff','BTC_high']], df_all.BTC_high)
Goal['BTC_high']= model.predict(Goal[['BTC_close_off_high_P','BTC_volatility_P','BTC_day_diff_P','BTC_high_P']])
Goal
| Date | BTC_close_off_high_P | BTC_volatility_P | BTC_day_diff_P | BTC_high_P | BTC_high | |
|---|---|---|---|---|---|---|
| Date | ||||||
| 2022-05-09 | 2022-05-09 | 0.427519 | 0.056620 | 0.004113 | 36408.188887 | 36461.826273 |
| 2022-05-10 | 2022-05-10 | 0.489442 | 0.042686 | -0.000152 | 36108.481592 | 36161.714806 |
| 2022-05-11 | 2022-05-11 | 0.452505 | 0.046211 | 0.006707 | 35808.774296 | 35861.556188 |
| 2022-05-12 | 2022-05-12 | 0.590630 | 0.053166 | -0.005631 | 35509.067000 | 35561.500604 |
| 2022-05-13 | 2022-05-13 | 0.518957 | 0.046965 | 0.000434 | 35209.359705 | 35261.315878 |
| 2022-05-14 | 2022-05-14 | 0.477256 | 0.026574 | 0.000475 | 34909.652409 | 34961.140094 |
| 2022-05-15 | 2022-05-15 | 0.507878 | 0.034869 | 0.001218 | 34609.945113 | 34661.023342 |
#predict BTC_close_off_high
fit1 = sm.tsa.statespace.SARIMAX(df_all.ADA_close_off_high,seasonal_order=(0,1,1,7)).fit()
Goal['ADA_close_off_high_P'] = fit1.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_volatility
fit2 = sm.tsa.statespace.SARIMAX(df_all.ADA_volatility,seasonal_order=(0,1,1,7)).fit()
Goal['ADA_volatility_P'] = fit2.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_day_diff
fit3 = sm.tsa.statespace.SARIMAX(df_all.ADA_day_diff,seasonal_order=(0,1,1,7)).fit()
Goal['ADA_day_diff_P'] = fit3.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_high
fit4 = Holt(np.asarray(df_all['ADA_high'])).fit(smoothing_level = 0.3,smoothing_slope = 0.1)
Goal['ADA_high_P'] = fit4.forecast(len(Goal))
#use suspective model to predict the target BTC_high
model = model.fit(df_all[['ADA_close_off_high','ADA_volatility','ADA_day_diff','ADA_high']], df_all.ADA_high)
Goal['ADA_high']= model.predict(Goal[['ADA_close_off_high_P','ADA_volatility_P','ADA_day_diff_P','ADA_high_P']])
#predict BTC_close_off_high
fit1 = sm.tsa.statespace.SARIMAX(df_all.ATOM_close_off_high,seasonal_order=(0,1,1,7)).fit()
Goal['ATOM_close_off_high_P'] = fit1.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_volatility
fit2 = sm.tsa.statespace.SARIMAX(df_all.ATOM_volatility,seasonal_order=(0,1,1,7)).fit()
Goal['ATOM_volatility_P'] = fit2.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_day_diff
fit3 = sm.tsa.statespace.SARIMAX(df_all.ATOM_day_diff,seasonal_order=(0,1,1,7)).fit()
Goal['ATOM_day_diff_P'] = fit3.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_high
fit4 = Holt(np.asarray(df_all['ATOM_high'])).fit(smoothing_level = 0.3,smoothing_slope = 0.1)
Goal['ATOM_high_P'] = fit4.forecast(len(Goal))
#use suspective model to predict the target BTC_high
model = model.fit(df_all[['ATOM_close_off_high','ATOM_volatility','ATOM_day_diff','ATOM_high']], df_all.ATOM_high)
Goal['ATOM_high']= model.predict(Goal[['ATOM_close_off_high_P','ATOM_volatility_P','ATOM_day_diff_P','ATOM_high_P']])
#predict BTC_close_off_high
fit1 = sm.tsa.statespace.SARIMAX(df_all.AVAX_close_off_high,seasonal_order=(0,1,1,7)).fit()
Goal['AVAX_close_off_high_P'] = fit1.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_volatility
fit2 = sm.tsa.statespace.SARIMAX(df_all.AVAX_volatility,seasonal_order=(0,1,1,7)).fit()
Goal['AVAX_volatility_P'] = fit2.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_day_diff
fit3 = sm.tsa.statespace.SARIMAX(df_all.AVAX_day_diff,seasonal_order=(0,1,1,7)).fit()
Goal['AVAX_day_diff_P'] = fit3.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_high
fit4 = Holt(np.asarray(df_all['AVAX_high'])).fit(smoothing_level = 0.3,smoothing_slope = 0.1)
Goal['AVAX_high_P'] = fit4.forecast(len(Goal))
#use suspective model to predict the target BTC_high
model = model.fit(df_all[['AVAX_close_off_high','AVAX_volatility','AVAX_day_diff','AVAX_high']], df_all.AVAX_high)
Goal['AVAX_high']= model.predict(Goal[['AVAX_close_off_high_P','AVAX_volatility_P','AVAX_day_diff_P','AVAX_high_P']])
#predict BTC_close_off_high
fit1 = sm.tsa.statespace.SARIMAX(df_all.AXS_close_off_high,seasonal_order=(0,1,1,7)).fit()
Goal['AXS_close_off_high_P'] = fit1.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_volatility
fit2 = sm.tsa.statespace.SARIMAX(df_all.AXS_volatility,seasonal_order=(0,1,1,7)).fit()
Goal['AXS_volatility_P'] = fit2.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_day_diff
fit3 = sm.tsa.statespace.SARIMAX(df_all.AXS_day_diff,seasonal_order=(0,1,1,7)).fit()
Goal['AXS_day_diff_P'] = fit3.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_high
fit4 = Holt(np.asarray(df_all['AXS_high'])).fit(smoothing_level = 0.3,smoothing_slope = 0.1)
Goal['AXS_high_P'] = fit4.forecast(len(Goal))
#use suspective model to predict the target BTC_high
model = model.fit(df_all[['AXS_close_off_high','AXS_volatility','AXS_day_diff','AXS_high']], df_all.AXS_high)
Goal['AXS_high']= model.predict(Goal[['AXS_close_off_high_P','AXS_volatility_P','AXS_day_diff_P','AXS_high_P']])
#predict BTC_close_off_high
fit1 = sm.tsa.statespace.SARIMAX(df_all.ETH_close_off_high,seasonal_order=(0,1,1,7)).fit()
Goal['ETH_close_off_high_P'] = fit1.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_volatility
fit2 = sm.tsa.statespace.SARIMAX(df_all.ETH_volatility,seasonal_order=(0,1,1,7)).fit()
Goal['ETH_volatility_P'] = fit2.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_day_diff
fit3 = sm.tsa.statespace.SARIMAX(df_all.ETH_day_diff,seasonal_order=(0,1,1,7)).fit()
Goal['ETH_day_diff_P'] = fit3.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_high
fit4 = Holt(np.asarray(df_all['ETH_high'])).fit(smoothing_level = 0.3,smoothing_slope = 0.1)
Goal['ETH_high_P'] = fit4.forecast(len(Goal))
#use suspective model to predict the target BTC_high
model = model.fit(df_all[['ETH_close_off_high','ETH_volatility','ETH_day_diff','ETH_high']], df_all.ETH_high)
Goal['ETH_high']= model.predict(Goal[['ETH_close_off_high_P','ETH_volatility_P','ETH_day_diff_P','ETH_high_P']])
#predict BTC_close_off_high
fit1 = sm.tsa.statespace.SARIMAX(df_all.LINK_close_off_high,seasonal_order=(0,1,1,7)).fit()
Goal['LINK_close_off_high_P'] = fit1.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_volatility
fit2 = sm.tsa.statespace.SARIMAX(df_all.LINK_volatility,seasonal_order=(0,1,1,7)).fit()
Goal['LINK_volatility_P'] = fit2.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_day_diff
fit3 = sm.tsa.statespace.SARIMAX(df_all.LINK_day_diff,seasonal_order=(0,1,1,7)).fit()
Goal['LINK_day_diff_P'] = fit3.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_high
fit4 = Holt(np.asarray(df_all['LINK_high'])).fit(smoothing_level = 0.3,smoothing_slope = 0.1)
Goal['LINK_high_P'] = fit4.forecast(len(Goal))
#use suspective model to predict the target BTC_high
model = model.fit(df_all[['LINK_close_off_high','LINK_volatility','LINK_day_diff','LINK_high']], df_all.LINK_high)
Goal['LINK_high']= model.predict(Goal[['LINK_close_off_high_P','LINK_volatility_P','LINK_day_diff_P','LINK_high_P']])
#predict BTC_close_off_high
fit1 = sm.tsa.statespace.SARIMAX(df_all.LUNA1_close_off_high,seasonal_order=(0,1,1,7)).fit()
Goal['LUNA1_close_off_high_P'] = fit1.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_volatility
fit2 = sm.tsa.statespace.SARIMAX(df_all.LUNA1_volatility,seasonal_order=(0,1,1,7)).fit()
Goal['LUNA1_volatility_P'] = fit2.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_day_diff
fit3 = sm.tsa.statespace.SARIMAX(df_all.LUNA1_day_diff,seasonal_order=(0,1,1,7)).fit()
Goal['LUNA1_day_diff_P'] = fit3.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_high
fit4 = Holt(np.asarray(df_all['LUNA1_high'])).fit(smoothing_level = 0.3,smoothing_slope = 0.1)
Goal['LUNA1_high_P'] = fit4.forecast(len(Goal))
#use suspective model to predict the target BTC_high
model = model.fit(df_all[['LUNA1_close_off_high','LUNA1_volatility','LUNA1_day_diff','LUNA1_high']], df_all.LUNA1_high)
Goal['LUNA1_high']= model.predict(Goal[['LUNA1_close_off_high_P','LUNA1_volatility_P','LUNA1_day_diff_P','LUNA1_high_P']])
#predict BTC_close_off_high
fit1 = sm.tsa.statespace.SARIMAX(df_all.MATIC_close_off_high,seasonal_order=(0,1,1,7)).fit()
Goal['MATIC_close_off_high_P'] = fit1.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_volatility
fit2 = sm.tsa.statespace.SARIMAX(df_all.MATIC_volatility,seasonal_order=(0,1,1,7)).fit()
Goal['MATIC_volatility_P'] = fit2.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_day_diff
fit3 = sm.tsa.statespace.SARIMAX(df_all.MATIC_day_diff,seasonal_order=(0,1,1,7)).fit()
Goal['MATIC_day_diff_P'] = fit3.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_high
fit4 = Holt(np.asarray(df_all['MATIC_high'])).fit(smoothing_level = 0.3,smoothing_slope = 0.1)
Goal['MATIC_high_P'] = fit4.forecast(len(Goal))
#use suspective model to predict the target BTC_high
model = model.fit(df_all[['MATIC_close_off_high','MATIC_volatility','MATIC_day_diff','MATIC_high']], df_all.MATIC_high)
Goal['MATIC_high']= model.predict(Goal[['MATIC_close_off_high_P','MATIC_volatility_P','MATIC_day_diff_P','MATIC_high_P']])
#predict BTC_close_off_high
fit1 = sm.tsa.statespace.SARIMAX(df_all.SOL_close_off_high,seasonal_order=(0,1,1,7)).fit()
Goal['SOL_close_off_high_P'] = fit1.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_volatility
fit2 = sm.tsa.statespace.SARIMAX(df_all.SOL_volatility,seasonal_order=(0,1,1,7)).fit()
Goal['SOL_volatility_P'] = fit2.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_day_diff
fit3 = sm.tsa.statespace.SARIMAX(df_all.SOL_day_diff,seasonal_order=(0,1,1,7)).fit()
Goal['SOL_day_diff_P'] = fit3.predict(start=Goal.Date.iloc[0], end=Goal.Date.iloc[-1], dynamic=True)
#predict BTC_high
fit4 = Holt(np.asarray(df_all['SOL_high'])).fit(smoothing_level = 0.3,smoothing_slope = 0.1)
Goal['SOL_high_P'] = fit4.forecast(len(Goal))
#use suspective model to predict the target BTC_high
model = model.fit(df_all[['SOL_close_off_high','SOL_volatility','SOL_day_diff','SOL_high']], df_all.SOL_high)
Goal['SOL_high']= model.predict(Goal[['SOL_close_off_high_P','SOL_volatility_P','SOL_day_diff_P','SOL_high_P']])
Result = Goal.copy()
Result = Result[[coin+metric for coin in ['ADA_', 'ATOM_','AVAX_', 'AXS_','BTC_', 'ETH_','LINK_', 'LUNA1_','MATIC_', 'SOL_']
for metric in ['high']]]
Result = Result.reset_index()
Result.columns = df_high.columns
Result = Result.T
new_header = Result.iloc[0] #grab the first row for the header
Result = Result[1:] #take the data less the header row
Result.columns = new_header #set the header row as the df header
Result
| Date | 2022-05-09 | 2022-05-10 | 2022-05-11 | 2022-05-12 | 2022-05-13 | 2022-05-14 | 2022-05-15 |
|---|---|---|---|---|---|---|---|
| ADA-USD | 0.775776 | 0.770371 | 0.760878 | 0.756281 | 0.74505 | 0.737446 | 0.731209 |
| ATOM-USD | 16.899498 | 16.514391 | 16.134255 | 15.74877 | 15.366182 | 14.982573 | 14.59856 |
| AVAX-USD | 56.749067 | 55.614314 | 54.479249 | 53.340977 | 52.206703 | 51.073925 | 49.934777 |
| AXS-USD | 28.280319 | 27.339405 | 26.40649 | 25.476397 | 24.534901 | 23.602397 | 22.665243 |
| BTC-USD | 36461.826273 | 36161.714806 | 35861.556188 | 35561.500604 | 35261.315878 | 34961.140094 | 34661.023342 |
| ETH-USD | 2709.151902 | 2687.367072 | 2665.558991 | 2643.817391 | 2622.005248 | 2600.181298 | 2578.402144 |
| LINK-USD | 11.220422 | 11.058664 | 10.826843 | 10.740801 | 10.506458 | 10.314653 | 10.126373 |
| LUNA1-USD | 76.280169 | 75.089411 | 73.910538 | 72.718771 | 71.536567 | 70.366927 | 69.179856 |
| MATIC-USD | 1.01409 | 0.995907 | 0.973173 | 0.951012 | 0.928394 | 0.904877 | 0.886285 |
| SOL-USD | 81.577121 | 80.160676 | 78.710086 | 77.300773 | 75.865539 | 74.407815 | 72.996647 |